| 725 |
chandransh |
1 |
package in.shop2020.creation.controllers;
|
|
|
2 |
|
| 1051 |
rajveer |
3 |
import in.shop2020.content.security.UserManager;
|
|
|
4 |
import in.shop2020.creation.util.ContentValidator;
|
|
|
5 |
import in.shop2020.metamodel.core.Entity;
|
|
|
6 |
import in.shop2020.metamodel.core.EntityState;
|
|
|
7 |
import in.shop2020.metamodel.util.CreationUtils;
|
| 725 |
chandransh |
8 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
|
|
9 |
|
| 1051 |
rajveer |
10 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
11 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
| 725 |
chandransh |
12 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
13 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
14 |
|
| 1051 |
rajveer |
15 |
@InterceptorRefs({
|
|
|
16 |
@InterceptorRef("myDefault"),
|
|
|
17 |
@InterceptorRef("login")
|
|
|
18 |
})
|
| 725 |
chandransh |
19 |
|
|
|
20 |
@Results({
|
|
|
21 |
@Result(name="success", type="redirectAction",
|
|
|
22 |
params = {"actionName" , "entity"})
|
|
|
23 |
})
|
| 1051 |
rajveer |
24 |
public class ItemUpdateController extends BaseController {
|
| 725 |
chandransh |
25 |
|
|
|
26 |
private static final long serialVersionUID = 7180013499003793197L;
|
|
|
27 |
|
|
|
28 |
private String id;
|
|
|
29 |
|
|
|
30 |
public String show(){
|
| 1051 |
rajveer |
31 |
if(this.reqparams.get("action") !=null){
|
| 725 |
chandransh |
32 |
long entityId = Long.parseLong(getId());
|
| 1051 |
rajveer |
33 |
String action = this.reqparams.get("action")[0];
|
|
|
34 |
|
|
|
35 |
if(action.equalsIgnoreCase("complete")){
|
|
|
36 |
if(!UserManager.getUserManager().canComplete(getUsername(), entityId)){
|
|
|
37 |
addActionError("Can not complete because this entity is not assigned to you.");
|
|
|
38 |
return "success";
|
|
|
39 |
}
|
|
|
40 |
try {
|
|
|
41 |
Entity entity = CreationUtils.getEntity(entityId);
|
|
|
42 |
ContentValidator validator = new ContentValidator();
|
|
|
43 |
if(!validator.validate(entity)){
|
|
|
44 |
addActionError("Entity is not yet complete because some mandatory fields are not filled.");
|
|
|
45 |
return "success";
|
|
|
46 |
}
|
|
|
47 |
EntityState state = CreationUtils.getEntityState(entityId);
|
|
|
48 |
state.completeEntity(this.getUsername());
|
|
|
49 |
CreationUtils.updateEntityState(state);
|
|
|
50 |
} catch (Exception e) {
|
|
|
51 |
e.printStackTrace();
|
|
|
52 |
}
|
|
|
53 |
addActionMessage("Entity completed successfully");
|
|
|
54 |
return "success";
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
if(action.equalsIgnoreCase("assign")){
|
|
|
58 |
if(this.reqparams.get("username") !=null){
|
|
|
59 |
if(!UserManager.getUserManager().canAssign(getUsername(), entityId)){
|
|
|
60 |
addActionError("You do not have rights to assign an entity");
|
|
|
61 |
return "success";
|
|
|
62 |
}
|
|
|
63 |
String assignTo = this.reqparams.get("username")[0];
|
|
|
64 |
System.out.println("User name is " + assignTo);
|
|
|
65 |
try {
|
|
|
66 |
EntityState state = CreationUtils.getEntityState(entityId);
|
|
|
67 |
state.assignEntity(this.getUsername(), assignTo);
|
|
|
68 |
CreationUtils.updateEntityState(state);
|
|
|
69 |
} catch (Exception e) {
|
|
|
70 |
e.printStackTrace();
|
|
|
71 |
}
|
|
|
72 |
addActionMessage("Entity assigned to " + assignTo + " successfully");
|
|
|
73 |
return "success";
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
if(action.equalsIgnoreCase("ready")){
|
|
|
79 |
if(!UserManager.getUserManager().canMarkReady(getUsername(), entityId)){
|
|
|
80 |
addActionError("You do not have rights to mark entity as ready");
|
|
|
81 |
return "success";
|
|
|
82 |
}
|
|
|
83 |
try {
|
| 2078 |
rajveer |
84 |
EntityState state = CreationUtils.getEntityState(entityId);
|
|
|
85 |
|
| 1051 |
rajveer |
86 |
CatalogServiceClient csc = new CatalogServiceClient();
|
|
|
87 |
in.shop2020.model.v1.catalog.InventoryService.Client iclient = csc.getClient();
|
| 2078 |
rajveer |
88 |
iclient.markItemAsContentComplete(entityId, state.getCategoryID(), state.getBrand(), state.getModelName(), state.getModelNumber());
|
| 1051 |
rajveer |
89 |
|
| 2078 |
rajveer |
90 |
|
| 1051 |
rajveer |
91 |
state.readyEntity(getUsername());
|
|
|
92 |
CreationUtils.updateEntityState(state);
|
| 1338 |
rajveer |
93 |
addActionMessage("Entity marked as ready successfully");
|
| 1051 |
rajveer |
94 |
} catch (Exception e) {
|
|
|
95 |
addActionError("Unable to mark entity as ready.");
|
|
|
96 |
e.printStackTrace();
|
|
|
97 |
}
|
|
|
98 |
return "success";
|
|
|
99 |
}
|
| 725 |
chandransh |
100 |
}
|
| 1051 |
rajveer |
101 |
addActionError("There is some problem, please contact admin.");
|
| 725 |
chandransh |
102 |
return "success";
|
|
|
103 |
}
|
|
|
104 |
|
| 1051 |
rajveer |
105 |
|
| 725 |
chandransh |
106 |
public String getId(){
|
|
|
107 |
return this.id;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
public void setId(String id){
|
|
|
111 |
this.id = id;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
}
|