Subversion Repositories SmartDukaan

Rev

Rev 725 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 725 Rev 1051
Line 1... Line 1...
1
package in.shop2020.creation.controllers;
1
package in.shop2020.creation.controllers;
2
 
2
 
-
 
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;
3
import in.shop2020.thrift.clients.CatalogServiceClient;
8
import in.shop2020.thrift.clients.CatalogServiceClient;
4
 
9
 
5
import java.util.Map;
-
 
6
 
-
 
7
import javax.servlet.http.HttpServletRequest;
-
 
8
import javax.servlet.http.HttpServletResponse;
-
 
9
 
-
 
10
import org.apache.juli.logging.Log;
10
import org.apache.struts2.convention.annotation.InterceptorRef;
11
import org.apache.juli.logging.LogFactory;
11
import org.apache.struts2.convention.annotation.InterceptorRefs;
12
import org.apache.struts2.convention.annotation.Result;
12
import org.apache.struts2.convention.annotation.Result;
13
import org.apache.struts2.convention.annotation.Results;
13
import org.apache.struts2.convention.annotation.Results;
14
import org.apache.struts2.interceptor.ParameterAware;
-
 
15
 
14
 
-
 
15
@InterceptorRefs({
16
import com.opensymphony.xwork2.ValidationAwareSupport;
16
    @InterceptorRef("myDefault"),
-
 
17
    @InterceptorRef("login")
-
 
18
})
17
 
19
 
18
@Results({
20
@Results({
19
    @Result(name="success", type="redirectAction", 
21
    @Result(name="success", type="redirectAction", 
20
    		params = {"actionName" , "entity"})
22
    		params = {"actionName" , "entity"})
21
})
23
})
22
public class ItemUpdateController extends ValidationAwareSupport implements ParameterAware {
24
public class ItemUpdateController extends BaseController {
23
	
25
	
24
	private static final long serialVersionUID = 7180013499003793197L;
26
	private static final long serialVersionUID = 7180013499003793197L;
25
	
27
	
26
	private Map<String, String[]> reqparams;
-
 
27
	
-
 
28
	private static Log log = LogFactory.getLog(ItemUpdateController.class);
-
 
29
	
-
 
30
	private String id;
28
	private String id;
31
	
29
	
32
	public String show(){
30
	public String show(){
33
		try {
-
 
34
			CatalogServiceClient csc = new CatalogServiceClient();
31
		if(this.reqparams.get("action") !=null){
35
			in.shop2020.model.v1.catalog.InventoryService.Client iclient = csc.getClient();
-
 
36
			long entityId = Long.parseLong(getId());
32
			long entityId = Long.parseLong(getId());
-
 
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 {
-
 
84
					CatalogServiceClient csc = new CatalogServiceClient();
-
 
85
					in.shop2020.model.v1.catalog.InventoryService.Client iclient = csc.getClient();
37
			iclient.markItemAsContentComplete(entityId);
86
					iclient.markItemAsContentComplete(entityId);	
-
 
87
					
-
 
88
					EntityState state = CreationUtils.getEntityState(entityId);
-
 
89
					state.readyEntity(getUsername());
-
 
90
					CreationUtils.updateEntityState(state);
38
		} catch (Exception e) {
91
				} catch (Exception e) {
-
 
92
					addActionError("Unable to mark entity as ready.");
39
			e.printStackTrace();
93
					e.printStackTrace();
-
 
94
				}
-
 
95
				addActionMessage("Entity marked as ready successfully");
-
 
96
				return "success";
-
 
97
			}
40
		}
98
		}
41
		addActionMessage("Entity updated successfully");
99
		addActionError("There is some problem, please contact admin.");
42
		return "success";
100
		return "success";
43
	}
101
	}
44
 
102
 
-
 
103
	
45
	public String getId(){
104
	public String getId(){
46
		return this.id;
105
		return this.id;
47
	}
106
	}
48
	
107
	
49
	public void setId(String id){
108
	public void setId(String id){
50
		this.id = id;
109
		this.id = id;
51
	}
110
	}
52
	
111
	
53
	@Override
-
 
54
	public void setParameters(Map<String, String[]> reqmap) {
-
 
55
		log.info("setParameters:" + reqmap);
-
 
56
		
-
 
57
		this.reqparams = reqmap;
-
 
58
	}
-
 
59
}
112
}