BrightSide Workbench Full Report + Source Code
bserp-www/src/main/java/org/turro/erp/task/logic/TaskWrapper.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.erp.task.logic;
19 
20 import java.util.HashMap;
21 import org.turro.auth.Authentication;
22 import org.turro.elephant.context.Application;
23 import org.turro.elephant.log.LogType;
24 import org.turro.erp.db.ErpPU;
25 import org.turro.erp.entity.*;
26 import org.turro.erp.menu.ErpMenu;
27 import org.turro.financials.model.business.CompanyWrapper;
28 
33 public class TaskWrapper extends org.turro.erp.task.TaskWrapper {
34 
36  super(entity);
37  }
38 
39  public String getTabLabel() {
40  return getSelfLabel() + " #" + entity.getId();
41  }
42 
43  public String getSelfLabel() {
44  return Application.getString("lTask");
45  }
46 
47  @Override
48  public boolean canDelete() {
49  if(entity.getId() == 0) return false;
50 // Dao dao = getDao();
51 // Long count = (Long) dao.getSingleResult(
52 // "select count(*) from Document " +
53 // "where contract = ?",
54 // new Object[] { contract });
55 // if(count == 0) {
56 // count = (Long) dao.getSingleResult(
57 // "select count(*) from DocumentLine " +
58 // "where store = ?",
59 // new Object[] { contract });
60 // }
61 // return count == 0;
62  return true;
63  }
64 
65  @Override
66  protected void logEntity(LogType logType, String path, String action, String data) {
67  Authentication.log(logType, path, action, data);
68  }
69 
70  public static void createTask(Task task, PredecessorType type) {
71  if(task == null || type == null) {
72  return;
73  }
74  Task t = new Task();
78  Predecessor predecessor = new Predecessor();
79  predecessor.setLag(0);
80  predecessor.setPredecessor(task);
81  predecessor.setTask(t);
82  predecessor.setType(type);
83  t.getPredecessors().add(predecessor);
84  HashMap<String, Object> map = new HashMap<String, Object>();
85  map.put("task", t);
86  ErpMenu.showModalZulFile("lNewTask", "/WEB-INF/_zul/erp/task/newTask.zul", map, null);
87  }
88 
89  public static void createTask(WorkOrder workOrder) {
90  if(workOrder == null) {
91  return;
92  }
93  createTask(findOrderReference(workOrder));
94  }
95 
96  public static void createTask(OrderReference orderReference) {
97  if(orderReference == null) {
98  return;
99  }
100  Task t = new Task();
102  t.setOrderReference(orderReference);
104  HashMap<String, Object> map = new HashMap<String, Object>();
105  map.put("task", t);
106  ErpMenu.showModalZulFile("lNewTask", "/WEB-INF/_zul/erp/task/newTask.zul", map, null);
107  }
108 
109 // public static Task createQuickTask(WorkOrder workOrder) {
110 // if(workOrder == null) {
111 // return null;
112 // }
113 // return createQuickTask(findOrderReference(workOrder));
114 // }
115 //
116 // public static Task createQuickTask(OrderReference orderReference) {
117 // if(orderReference == null) {
118 // return null;
119 // }
120 // Task t = new Task();
121 // t.setStatus(TaskStatus.TASK_PLANNING);
122 // t.setName(Application.getString("lTask"));
123 //
124 // t.setOrderReference(orderReference);
125 // t.getOrderReference().getTasks().add(t);
126 // t.setSupervised(t.getOrderReference().getWorkOrder().getSupervised());
127 // HashMap<String, Object> map = new HashMap<String, Object>();
128 // map.put("task", t);
129 // ErpMenu.showModalZulFile("lNewTask", "/WEB-INF/_zul/erp/task/quickTask.zul", map);
130 // return (t.getOrderReference().isEmpty() || t.isEmpty()) ? null : t;
131 // }
132 //
133 // public static OrderReference createQuickReference(WorkOrder workOrder) {
134 // if(workOrder == null) {
135 // return null;
136 // }
137 // OrderReference or = new OrderReference();
138 // or.setOrderRef(1);
139 // or.setValidated(false);
140 // or.setWorkOrder(workOrder);
141 // or.setDescription(Application.getString("lReference"));
142 // or.setService(CompanyWrapper.getDefaultContractService());
143 // workOrder.getOrderReferences().add(or);
144 // HashMap<String, Object> map = new HashMap<String, Object>();
145 // map.put("reference", or);
146 // ErpMenu.showModalZulFile("lNewReference", "/WEB-INF/_zul/erp/task/quickReference.zul", map);
147 // return or.isEmpty() ? null : or;
148 // }
149 
150  private static OrderReference findOrderReference(WorkOrder workOrder) {
151  //TODO: What if there were more than one reference?
152  for(OrderReference or : workOrder.getOrderReferences()) {
153  return or;
154  }
155  OrderReference or = new OrderReference();
156  or.setOrderRef(1);
157  or.setValidated(false);
158  or.setWorkOrder(workOrder);
159  or.setDescription(Application.getString("lReference"));
161  or = new ErpPU().saveObject(or);
162  workOrder.getOrderReferences().add(or);
163  return or;
164  }
165 
166 }
static String getString(String key)
void setValidated(boolean validated)
void setWorkOrder(WorkOrder workOrder)
void setDescription(String description)
void setType(PredecessorType type)
void setPredecessor(Task predecessor)
Set< OrderReference > getOrderReferences()
Definition: WorkOrder.java:124
void logEntity(LogType logType, String path, String action, String data)