| Line 1... |
Line 1... |
| 1 |
package in.shop2020.creation.controllers;
|
1 |
package in.shop2020.creation.controllers;
|
| 2 |
|
2 |
|
| 3 |
import java.util.ArrayList;
|
- |
|
| 4 |
import java.util.Calendar;
|
- |
|
| 5 |
import java.util.List;
|
- |
|
| 6 |
|
- |
|
| 7 |
import in.shop2020.content.security.UserManager;
|
3 |
import in.shop2020.content.security.UserManager;
|
| 8 |
import in.shop2020.creation.util.ContentValidator;
|
4 |
import in.shop2020.creation.util.ContentValidator;
|
| 9 |
import in.shop2020.metamodel.core.Entity;
|
5 |
import in.shop2020.metamodel.core.Entity;
|
| 10 |
import in.shop2020.metamodel.core.EntityState;
|
6 |
import in.shop2020.metamodel.core.EntityState;
|
| 11 |
import in.shop2020.metamodel.core.EntityStatus;
|
7 |
import in.shop2020.metamodel.core.EntityStatus;
|
| - |
|
8 |
import in.shop2020.metamodel.core.Slide;
|
| 12 |
import in.shop2020.metamodel.util.CreationUtils;
|
9 |
import in.shop2020.metamodel.util.CreationUtils;
|
| 13 |
import in.shop2020.thrift.clients.CatalogClient;
|
10 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 14 |
|
11 |
|
| - |
|
12 |
import java.io.ByteArrayInputStream;
|
| - |
|
13 |
import java.io.ByteArrayOutputStream;
|
| - |
|
14 |
import java.io.ObjectInputStream;
|
| - |
|
15 |
import java.io.ObjectOutputStream;
|
| - |
|
16 |
import java.util.ArrayList;
|
| - |
|
17 |
import java.util.Calendar;
|
| - |
|
18 |
import java.util.List;
|
| - |
|
19 |
|
| - |
|
20 |
import org.apache.juli.logging.Log;
|
| - |
|
21 |
import org.apache.juli.logging.LogFactory;
|
| 15 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
22 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
| 16 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
23 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
| 17 |
import org.apache.struts2.convention.annotation.Result;
|
24 |
import org.apache.struts2.convention.annotation.Result;
|
| 18 |
import org.apache.struts2.convention.annotation.Results;
|
25 |
import org.apache.struts2.convention.annotation.Results;
|
| 19 |
|
26 |
|
| Line 30... |
Line 37... |
| 30 |
|
37 |
|
| 31 |
private static final long serialVersionUID = 7180013499003793197L;
|
38 |
private static final long serialVersionUID = 7180013499003793197L;
|
| 32 |
|
39 |
|
| 33 |
private String id;
|
40 |
private String id;
|
| 34 |
|
41 |
|
| - |
|
42 |
private static Log log = LogFactory.getLog(ItemUpdateController.class);
|
| - |
|
43 |
|
| 35 |
public String show(){
|
44 |
public String show(){
|
| 36 |
if(this.reqparams.get("action") !=null){
|
45 |
if(this.reqparams.get("action") !=null){
|
| 37 |
long entityId = Long.parseLong(getId());
|
46 |
long entityId = Long.parseLong(getId());
|
| 38 |
String action = this.reqparams.get("action")[0];
|
47 |
String action = this.reqparams.get("action")[0];
|
| 39 |
|
48 |
|
| Line 93... |
Line 102... |
| 93 |
addActionMessage("Entity assigned to " + assignTo + " successfully");
|
102 |
addActionMessage("Entity assigned to " + assignTo + " successfully");
|
| 94 |
return "success";
|
103 |
return "success";
|
| 95 |
}
|
104 |
}
|
| 96 |
}
|
105 |
}
|
| 97 |
|
106 |
|
| - |
|
107 |
if (action.equalsIgnoreCase("dup-entity")) {
|
| - |
|
108 |
if (!UserManager.getUserManager().canAssign(getUsername(),
|
| - |
|
109 |
entityId)) {
|
| - |
|
110 |
addActionError("You do not have rights to clone entites.");
|
| - |
|
111 |
return "success";
|
| - |
|
112 |
}
|
| - |
|
113 |
String dupEntityId = this.reqparams.get("entity-old")[0];
|
| - |
|
114 |
log.info("Duplicate Entity is " + dupEntityId);
|
| - |
|
115 |
try {
|
| - |
|
116 |
Entity newEntity = CreationUtils.getEntity(entityId);
|
| - |
|
117 |
Entity dupEntity = CreationUtils.getEntity(Long
|
| - |
|
118 |
.parseLong(dupEntityId));
|
| - |
|
119 |
List<Slide> slides = dupEntity.getSlides();
|
| - |
|
120 |
List<Slide> newSlides = new ArrayList<Slide>();
|
| - |
|
121 |
for (Slide slide : slides) {
|
| - |
|
122 |
// Serializing and deserializing to clone the slide
|
| - |
|
123 |
// serialize
|
| - |
|
124 |
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
| - |
|
125 |
ObjectOutputStream out = new ObjectOutputStream(bos);
|
| - |
|
126 |
out.writeObject(slide);
|
| - |
|
127 |
|
| - |
|
128 |
// De-serialization
|
| - |
|
129 |
ByteArrayInputStream bis = new ByteArrayInputStream(
|
| - |
|
130 |
bos.toByteArray());
|
| - |
|
131 |
ObjectInputStream in = new ObjectInputStream(bis);
|
| - |
|
132 |
Slide newSlide = (Slide) in.readObject();
|
| - |
|
133 |
newSlides.add(newSlide);
|
| - |
|
134 |
}
|
| - |
|
135 |
|
| - |
|
136 |
List<Long> slideSequence = dupEntity.getSlideSequence();
|
| - |
|
137 |
List<Long> newSlideSequence = new ArrayList<Long>(slideSequence);
|
| - |
|
138 |
newEntity.setSlides(newSlides);
|
| - |
|
139 |
newEntity.setSlideSequence(newSlideSequence);
|
| - |
|
140 |
CreationUtils.updateEntity(newEntity);
|
| - |
|
141 |
} catch (Exception e) {
|
| - |
|
142 |
addActionError(dupEntityId + "is not a valid Entity.");
|
| - |
|
143 |
e.printStackTrace();
|
| - |
|
144 |
return "success";
|
| - |
|
145 |
}
|
| - |
|
146 |
addActionMessage("Entity " + entityId + " has been cloned successfully");
|
| - |
|
147 |
return "success";
|
| - |
|
148 |
}
|
| - |
|
149 |
|
| 98 |
|
150 |
|
| 99 |
if(action.equalsIgnoreCase("ready")){
|
151 |
if(action.equalsIgnoreCase("ready")){
|
| 100 |
if(!UserManager.getUserManager().canMarkReady(getUsername(), entityId)){
|
152 |
if(!UserManager.getUserManager().canMarkReady(getUsername(), entityId)){
|
| 101 |
addActionError("You do not have rights to mark entity as ready");
|
153 |
addActionError("You do not have rights to mark entity as ready");
|
| 102 |
return "success";
|
154 |
return "success";
|