| 725 |
chandransh |
1 |
package in.shop2020.creation.controllers;
|
|
|
2 |
|
| 2095 |
rajveer |
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.Calendar;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
|
| 1051 |
rajveer |
7 |
import in.shop2020.content.security.UserManager;
|
|
|
8 |
import in.shop2020.creation.util.ContentValidator;
|
|
|
9 |
import in.shop2020.metamodel.core.Entity;
|
|
|
10 |
import in.shop2020.metamodel.core.EntityState;
|
| 2095 |
rajveer |
11 |
import in.shop2020.metamodel.core.EntityStatus;
|
| 1051 |
rajveer |
12 |
import in.shop2020.metamodel.util.CreationUtils;
|
| 3127 |
rajveer |
13 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 725 |
chandransh |
14 |
|
| 1051 |
rajveer |
15 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
16 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
| 725 |
chandransh |
17 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
18 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
19 |
|
| 1051 |
rajveer |
20 |
@InterceptorRefs({
|
|
|
21 |
@InterceptorRef("myDefault"),
|
|
|
22 |
@InterceptorRef("login")
|
|
|
23 |
})
|
| 725 |
chandransh |
24 |
|
|
|
25 |
@Results({
|
|
|
26 |
@Result(name="success", type="redirectAction",
|
|
|
27 |
params = {"actionName" , "entity"})
|
|
|
28 |
})
|
| 1051 |
rajveer |
29 |
public class ItemUpdateController extends BaseController {
|
| 725 |
chandransh |
30 |
|
|
|
31 |
private static final long serialVersionUID = 7180013499003793197L;
|
|
|
32 |
|
|
|
33 |
private String id;
|
|
|
34 |
|
|
|
35 |
public String show(){
|
| 1051 |
rajveer |
36 |
if(this.reqparams.get("action") !=null){
|
| 725 |
chandransh |
37 |
long entityId = Long.parseLong(getId());
|
| 1051 |
rajveer |
38 |
String action = this.reqparams.get("action")[0];
|
|
|
39 |
|
|
|
40 |
if(action.equalsIgnoreCase("complete")){
|
|
|
41 |
if(!UserManager.getUserManager().canComplete(getUsername(), entityId)){
|
|
|
42 |
addActionError("Can not complete because this entity is not assigned to you.");
|
|
|
43 |
return "success";
|
|
|
44 |
}
|
|
|
45 |
try {
|
|
|
46 |
Entity entity = CreationUtils.getEntity(entityId);
|
|
|
47 |
ContentValidator validator = new ContentValidator();
|
|
|
48 |
if(!validator.validate(entity)){
|
|
|
49 |
addActionError("Entity is not yet complete because some mandatory fields are not filled.");
|
|
|
50 |
return "success";
|
|
|
51 |
}
|
|
|
52 |
EntityState state = CreationUtils.getEntityState(entityId);
|
|
|
53 |
state.completeEntity(this.getUsername());
|
|
|
54 |
CreationUtils.updateEntityState(state);
|
|
|
55 |
} catch (Exception e) {
|
|
|
56 |
e.printStackTrace();
|
|
|
57 |
}
|
|
|
58 |
addActionMessage("Entity completed successfully");
|
|
|
59 |
return "success";
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
if(action.equalsIgnoreCase("assign")){
|
|
|
63 |
if(this.reqparams.get("username") !=null){
|
| 2095 |
rajveer |
64 |
if(!UserManager.getUserManager().canAssign(getUsername(), entityId)){
|
| 1051 |
rajveer |
65 |
addActionError("You do not have rights to assign an entity");
|
|
|
66 |
return "success";
|
|
|
67 |
}
|
|
|
68 |
String assignTo = this.reqparams.get("username")[0];
|
|
|
69 |
System.out.println("User name is " + assignTo);
|
|
|
70 |
try {
|
|
|
71 |
EntityState state = CreationUtils.getEntityState(entityId);
|
| 2095 |
rajveer |
72 |
if(state.getStatus() == EntityStatus.READY){
|
|
|
73 |
Calendar cl = Calendar.getInstance();
|
| 4011 |
rajveer |
74 |
int hourOfDay = cl.get(Calendar.HOUR_OF_DAY);
|
| 4012 |
rajveer |
75 |
int minuteOfHour = cl.get(Calendar.MINUTE);
|
| 4011 |
rajveer |
76 |
int totalMinutes = 60*hourOfDay + minuteOfHour;
|
|
|
77 |
if(totalMinutes > 14*60 + 45 && totalMinutes < 15*60 + 30){
|
| 4012 |
rajveer |
78 |
addActionError("Sorry.... This is not right time to assign this entity. Please visit after 3.30 PM.");
|
| 2095 |
rajveer |
79 |
return "success";
|
|
|
80 |
}
|
|
|
81 |
List<Long> inconsistentEntities = CreationUtils.getInconsistentEntities();
|
|
|
82 |
if(inconsistentEntities == null){
|
|
|
83 |
inconsistentEntities = new ArrayList<Long>();
|
|
|
84 |
}
|
|
|
85 |
inconsistentEntities.add(state.getID());
|
|
|
86 |
CreationUtils.storeInconsistentEntities(inconsistentEntities);
|
|
|
87 |
}
|
| 1051 |
rajveer |
88 |
state.assignEntity(this.getUsername(), assignTo);
|
|
|
89 |
CreationUtils.updateEntityState(state);
|
|
|
90 |
} catch (Exception e) {
|
|
|
91 |
e.printStackTrace();
|
|
|
92 |
}
|
|
|
93 |
addActionMessage("Entity assigned to " + assignTo + " successfully");
|
|
|
94 |
return "success";
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
if(action.equalsIgnoreCase("ready")){
|
|
|
100 |
if(!UserManager.getUserManager().canMarkReady(getUsername(), entityId)){
|
|
|
101 |
addActionError("You do not have rights to mark entity as ready");
|
|
|
102 |
return "success";
|
|
|
103 |
}
|
|
|
104 |
try {
|
| 2078 |
rajveer |
105 |
EntityState state = CreationUtils.getEntityState(entityId);
|
|
|
106 |
|
| 3127 |
rajveer |
107 |
CatalogClient csc = new CatalogClient();
|
| 1051 |
rajveer |
108 |
in.shop2020.model.v1.catalog.InventoryService.Client iclient = csc.getClient();
|
| 2078 |
rajveer |
109 |
iclient.markItemAsContentComplete(entityId, state.getCategoryID(), state.getBrand(), state.getModelName(), state.getModelNumber());
|
| 1051 |
rajveer |
110 |
|
| 2095 |
rajveer |
111 |
List<Long> inconsistentEntities = CreationUtils.getInconsistentEntities();
|
|
|
112 |
if(inconsistentEntities != null){
|
|
|
113 |
inconsistentEntities.remove(state.getID());
|
|
|
114 |
CreationUtils.storeInconsistentEntities(inconsistentEntities);
|
|
|
115 |
}
|
| 2078 |
rajveer |
116 |
|
| 1051 |
rajveer |
117 |
state.readyEntity(getUsername());
|
|
|
118 |
CreationUtils.updateEntityState(state);
|
| 1338 |
rajveer |
119 |
addActionMessage("Entity marked as ready successfully");
|
| 1051 |
rajveer |
120 |
} catch (Exception e) {
|
|
|
121 |
addActionError("Unable to mark entity as ready.");
|
|
|
122 |
e.printStackTrace();
|
|
|
123 |
}
|
|
|
124 |
return "success";
|
|
|
125 |
}
|
| 4011 |
rajveer |
126 |
|
|
|
127 |
|
|
|
128 |
if(action.equalsIgnoreCase("iteminfo")){
|
|
|
129 |
return "iteminfo";
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
|
| 725 |
chandransh |
133 |
}
|
| 1051 |
rajveer |
134 |
addActionError("There is some problem, please contact admin.");
|
| 725 |
chandransh |
135 |
return "success";
|
|
|
136 |
}
|
|
|
137 |
|
| 1051 |
rajveer |
138 |
|
| 725 |
chandransh |
139 |
public String getId(){
|
|
|
140 |
return this.id;
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
public void setId(String id){
|
|
|
144 |
this.id = id;
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
}
|