| 162 |
naveen |
1 |
package in.shop2020.creation.controllers;
|
|
|
2 |
|
| 1051 |
rajveer |
3 |
import in.shop2020.content.security.User;
|
|
|
4 |
import in.shop2020.content.security.UserManager;
|
| 201 |
naveen |
5 |
import in.shop2020.metamodel.core.Bullet;
|
| 204 |
naveen |
6 |
import in.shop2020.metamodel.core.CompositeDataObject;
|
| 162 |
naveen |
7 |
import in.shop2020.metamodel.core.Entity;
|
| 1051 |
rajveer |
8 |
import in.shop2020.metamodel.core.EntityState;
|
| 7964 |
amit.gupta |
9 |
import in.shop2020.metamodel.core.EntityStatus;
|
| 204 |
naveen |
10 |
import in.shop2020.metamodel.core.EnumDataObject;
|
| 201 |
naveen |
11 |
import in.shop2020.metamodel.core.Feature;
|
| 198 |
naveen |
12 |
import in.shop2020.metamodel.core.FreeformContent;
|
| 201 |
naveen |
13 |
import in.shop2020.metamodel.core.PrimitiveDataObject;
|
| 198 |
naveen |
14 |
import in.shop2020.metamodel.core.Slide;
|
| 242 |
naveen |
15 |
import in.shop2020.metamodel.definitions.Catalog;
|
| 198 |
naveen |
16 |
import in.shop2020.metamodel.definitions.Category;
|
| 4959 |
amit.gupta |
17 |
import in.shop2020.metamodel.definitions.ChildSlideDefinition;
|
| 204 |
naveen |
18 |
import in.shop2020.metamodel.definitions.CompositeDefinition;
|
|
|
19 |
import in.shop2020.metamodel.definitions.CompositePartDefinition;
|
| 198 |
naveen |
20 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
| 310 |
rajveer |
21 |
import in.shop2020.metamodel.definitions.EditorialImportance;
|
| 201 |
naveen |
22 |
import in.shop2020.metamodel.definitions.FeatureDefinition;
|
|
|
23 |
import in.shop2020.metamodel.definitions.SlideDefinition;
|
|
|
24 |
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
|
| 4129 |
mandeep.dh |
25 |
import in.shop2020.metamodel.util.CreationUtils;
|
| 198 |
naveen |
26 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
| 201 |
naveen |
27 |
import in.shop2020.metamodel.util.ExpandedBulletDefinition;
|
| 162 |
naveen |
28 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
| 201 |
naveen |
29 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
|
|
30 |
import in.shop2020.metamodel.util.ExpandedFeatureDefinition;
|
| 198 |
naveen |
31 |
import in.shop2020.metamodel.util.ExpandedSlide;
|
|
|
32 |
import in.shop2020.metamodel.util.ExpandedSlideDefinition;
|
| 5945 |
mandeep.dh |
33 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
| 739 |
chandransh |
34 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
35 |
import in.shop2020.model.v1.catalog.status;
|
| 3127 |
rajveer |
36 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 7958 |
amit.gupta |
37 |
import in.shop2020.util.NewCMP;
|
| 162 |
naveen |
38 |
import in.shop2020.util.Utils;
|
|
|
39 |
|
| 7962 |
amit.gupta |
40 |
import java.text.DecimalFormat;
|
| 5760 |
amit.gupta |
41 |
import java.text.MessageFormat;
|
| 4129 |
mandeep.dh |
42 |
import java.text.SimpleDateFormat;
|
| 208 |
naveen |
43 |
import java.util.ArrayList;
|
|
|
44 |
import java.util.Arrays;
|
|
|
45 |
import java.util.Collection;
|
| 4129 |
mandeep.dh |
46 |
import java.util.Date;
|
| 208 |
naveen |
47 |
import java.util.HashMap;
|
|
|
48 |
import java.util.List;
|
| 6877 |
amit.gupta |
49 |
import java.util.Locale;
|
| 208 |
naveen |
50 |
import java.util.Map;
|
| 1051 |
rajveer |
51 |
import java.util.Set;
|
| 450 |
rajveer |
52 |
import java.util.StringTokenizer;
|
| 208 |
naveen |
53 |
|
| 5180 |
amit.gupta |
54 |
import org.apache.commons.lang.StringEscapeUtils;
|
| 208 |
naveen |
55 |
import org.apache.commons.lang.StringUtils;
|
| 162 |
naveen |
56 |
import org.apache.juli.logging.Log;
|
|
|
57 |
import org.apache.juli.logging.LogFactory;
|
| 1051 |
rajveer |
58 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
59 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
| 162 |
naveen |
60 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
61 |
import org.apache.struts2.convention.annotation.Results;
|
| 208 |
naveen |
62 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
63 |
import org.apache.struts2.rest.HttpHeaders;
|
| 4129 |
mandeep.dh |
64 |
import org.apache.thrift.TException;
|
| 162 |
naveen |
65 |
|
| 242 |
naveen |
66 |
|
| 1051 |
rajveer |
67 |
@InterceptorRefs({
|
|
|
68 |
@InterceptorRef("myDefault"),
|
|
|
69 |
@InterceptorRef("login")
|
|
|
70 |
})
|
|
|
71 |
|
| 162 |
naveen |
72 |
@Results({
|
|
|
73 |
@Result(name="success", type="redirectAction",
|
| 198 |
naveen |
74 |
params = {"actionName" , "entity"}),
|
|
|
75 |
@Result(name="redirect", location="${url}", type="redirect")
|
| 162 |
naveen |
76 |
})
|
| 242 |
naveen |
77 |
|
| 1051 |
rajveer |
78 |
public class EntityController extends BaseController {
|
| 162 |
naveen |
79 |
|
|
|
80 |
/**
|
|
|
81 |
*
|
|
|
82 |
*/
|
| 242 |
naveen |
83 |
private static final long serialVersionUID = 1L;
|
| 6894 |
amit.gupta |
84 |
|
| 7100 |
amit.gupta |
85 |
private static Date lastEntityCreation = new Date(System.currentTimeMillis() - (60 * 60 * 1000));
|
| 242 |
naveen |
86 |
|
|
|
87 |
/**
|
|
|
88 |
*
|
|
|
89 |
*/
|
| 162 |
naveen |
90 |
private static Log log = LogFactory.getLog(EntityController.class);
|
|
|
91 |
|
|
|
92 |
/**
|
|
|
93 |
*
|
|
|
94 |
*/
|
|
|
95 |
private String id;
|
|
|
96 |
|
| 6877 |
amit.gupta |
97 |
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH", Locale.ENGLISH);
|
|
|
98 |
|
| 162 |
naveen |
99 |
private ExpandedEntity expEntity;
|
|
|
100 |
|
| 1051 |
rajveer |
101 |
private Entity entity = null;
|
| 250 |
naveen |
102 |
|
| 1051 |
rajveer |
103 |
private Map<Long, EntityState> entitiesState;
|
| 162 |
naveen |
104 |
|
| 1051 |
rajveer |
105 |
private DefinitionsContainer defs = Catalog.getInstance().getDefinitionsContainer();
|
| 198 |
naveen |
106 |
|
| 213 |
naveen |
107 |
private long firstSlideDefID;
|
| 198 |
naveen |
108 |
|
|
|
109 |
private ExpandedSlideDefinition expSlideDef;
|
|
|
110 |
|
|
|
111 |
private ExpandedSlide expSlide;
|
|
|
112 |
|
|
|
113 |
private String redirectURL;
|
|
|
114 |
|
|
|
115 |
private Exception exception;
|
|
|
116 |
|
|
|
117 |
private String errorString;
|
|
|
118 |
|
|
|
119 |
private long newCurrentSlideDefinitionID;
|
|
|
120 |
|
|
|
121 |
private long newNextSlideDefinitionID;
|
|
|
122 |
|
|
|
123 |
private long newPrevSlideDefinitionID;
|
| 242 |
naveen |
124 |
|
| 250 |
naveen |
125 |
private Map<Long, List<Long>> catSlides;
|
| 516 |
rajveer |
126 |
|
|
|
127 |
private Map<Long, List<Entity>> catEntities;
|
| 1051 |
rajveer |
128 |
|
| 2095 |
rajveer |
129 |
private List<Long> inconsistentEntities;
|
| 4129 |
mandeep.dh |
130 |
|
|
|
131 |
private long entityId;
|
|
|
132 |
private List<Item> items;
|
|
|
133 |
|
|
|
134 |
// GET /entity/1
|
| 242 |
naveen |
135 |
public String show() {
|
|
|
136 |
log.info("EntityController.show");
|
|
|
137 |
|
|
|
138 |
try {
|
|
|
139 |
long entityID = Long.parseLong(this.getId());
|
|
|
140 |
log.info("entityID:" + entityID);
|
|
|
141 |
|
| 1051 |
rajveer |
142 |
if(!UserManager.getUserManager().canView(getUsername(), entityID)){
|
|
|
143 |
return "fatel";
|
|
|
144 |
}
|
|
|
145 |
|
| 250 |
naveen |
146 |
this.expEntity = this.getExpandedEntity(entityID);
|
| 242 |
naveen |
147 |
|
|
|
148 |
return "show";
|
|
|
149 |
} catch (Exception e) {
|
|
|
150 |
log.error(CreationUtils.getStackTrace(e));
|
|
|
151 |
this.setErrorString(CreationUtils.getStackTrace(e));
|
|
|
152 |
return "fatal";
|
|
|
153 |
}
|
|
|
154 |
}
|
| 198 |
naveen |
155 |
|
| 162 |
naveen |
156 |
// GET /entity
|
|
|
157 |
public HttpHeaders index() {
|
|
|
158 |
log.info("EntityController.index");
|
| 1152 |
rajveer |
159 |
|
| 162 |
naveen |
160 |
try {
|
| 1051 |
rajveer |
161 |
this.entitiesState = CreationUtils.getEntitiesState();
|
| 2095 |
rajveer |
162 |
inconsistentEntities = CreationUtils.getInconsistentEntities();
|
| 1152 |
rajveer |
163 |
//Must be called after getting entities state
|
|
|
164 |
createEntitiesForItemsInProcess();
|
| 2095 |
rajveer |
165 |
|
| 162 |
naveen |
166 |
} catch (Exception e) {
|
| 208 |
naveen |
167 |
log.error(CreationUtils.getStackTrace(e));
|
|
|
168 |
this.setErrorString(CreationUtils.getStackTrace(e));
|
| 198 |
naveen |
169 |
return new DefaultHttpHeaders("fatal");
|
| 162 |
naveen |
170 |
}
|
|
|
171 |
|
| 208 |
naveen |
172 |
return new DefaultHttpHeaders("index").disableCaching();
|
| 162 |
naveen |
173 |
}
|
|
|
174 |
|
|
|
175 |
// GET /entity
|
|
|
176 |
public String create() {
|
|
|
177 |
log.info("EntityController.create");
|
|
|
178 |
|
| 1051 |
rajveer |
179 |
if(!UserManager.getUserManager().canCreate(getUsername())){
|
|
|
180 |
return "success";
|
|
|
181 |
}
|
|
|
182 |
|
| 162 |
naveen |
183 |
try {
|
| 1152 |
rajveer |
184 |
// Generate new entityID from cms
|
| 3127 |
rajveer |
185 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 1152 |
rajveer |
186 |
long entityID = catalogServiceClient.getClient().generateNewEntityID();
|
|
|
187 |
|
| 162 |
naveen |
188 |
String categoryID = this.reqparams.get("category")[0];
|
|
|
189 |
Entity entity = new Entity(entityID, Long.parseLong(categoryID));
|
|
|
190 |
|
| 2607 |
rajveer |
191 |
entity.setBrand((this.reqparams.get("brand")[0]).trim());
|
|
|
192 |
entity.setModelName((this.reqparams.get("modelname")[0]).trim());
|
|
|
193 |
entity.setModelNumber((this.reqparams.get("modelnumber")[0]).trim());
|
| 162 |
naveen |
194 |
|
| 1152 |
rajveer |
195 |
EntityState entityState = new EntityState(entityID, Long.parseLong(categoryID), getUsername());
|
| 2607 |
rajveer |
196 |
entityState.setBrand((this.reqparams.get("brand")[0]).trim());
|
|
|
197 |
entityState.setModelName((this.reqparams.get("modelname")[0]).trim());
|
|
|
198 |
entityState.setModelNumber((this.reqparams.get("modelnumber")[0]).trim());
|
| 162 |
naveen |
199 |
|
| 2607 |
rajveer |
200 |
|
| 1051 |
rajveer |
201 |
CreationUtils.createEntity(entity, entityState);
|
|
|
202 |
|
| 162 |
naveen |
203 |
this.setId(new Long(entityID).toString());
|
|
|
204 |
} catch (Exception e) {
|
| 208 |
naveen |
205 |
log.error(CreationUtils.getStackTrace(e));
|
|
|
206 |
this.setErrorString(CreationUtils.getStackTrace(e));
|
| 198 |
naveen |
207 |
return "fatal";
|
| 162 |
naveen |
208 |
}
|
| 198 |
naveen |
209 |
|
|
|
210 |
this.redirectURL = "entity/" + this.getId() + "/edit";
|
| 162 |
naveen |
211 |
|
| 198 |
naveen |
212 |
return "redirect";
|
| 162 |
naveen |
213 |
}
|
|
|
214 |
|
|
|
215 |
// GET /entity/1/edit
|
|
|
216 |
public String edit() {
|
|
|
217 |
log.info("EntityController.edit");
|
|
|
218 |
|
|
|
219 |
long entityID = Long.parseLong(this.getId());
|
|
|
220 |
log.info("entityID:" + entityID);
|
| 1051 |
rajveer |
221 |
if(!UserManager.getUserManager().canEdit(getUsername(), entityID)){
|
|
|
222 |
addActionError("You can not edit as this entity is not assigned to you");
|
|
|
223 |
return "success";
|
|
|
224 |
}
|
| 162 |
naveen |
225 |
|
|
|
226 |
try {
|
| 250 |
naveen |
227 |
this.expEntity = this.getExpandedEntity(entityID);
|
| 198 |
naveen |
228 |
//log.info("this.expEntity:" + this.expEntity);
|
| 242 |
naveen |
229 |
|
|
|
230 |
String[] inputSlideDefIDs = this.reqparams.get("slideDefID");
|
|
|
231 |
long inputSlideDefID = 0L;
|
|
|
232 |
if(inputSlideDefIDs != null && inputSlideDefIDs.length > 0) {
|
|
|
233 |
try {
|
|
|
234 |
inputSlideDefID = Long.parseLong(inputSlideDefIDs[0]);
|
|
|
235 |
} catch (NumberFormatException nfe) {}
|
|
|
236 |
}
|
| 1051 |
rajveer |
237 |
long categoryID = CreationUtils.getEntity(entityID).getCategoryID();
|
| 310 |
rajveer |
238 |
|
|
|
239 |
log.info("Entity ID:" + entityID + " CategoryID " + categoryID );
|
| 1051 |
rajveer |
240 |
|
| 310 |
rajveer |
241 |
//Changed to make correct order of borrowed slides
|
| 1051 |
rajveer |
242 |
//List<Long> slideDefIDs = CreationUtils.getSlideSequence(entityID, categoryID);
|
| 310 |
rajveer |
243 |
|
| 1051 |
rajveer |
244 |
List<Long> slideDefIDs = expEntity.getSlideSequence();
|
| 242 |
naveen |
245 |
log.info("slideDefIDs:" + slideDefIDs);
|
| 1051 |
rajveer |
246 |
if(slideDefIDs == null){
|
|
|
247 |
slideDefIDs = Catalog.getInstance().getDefinitionsContainer().getCategorySlideSequence(categoryID);
|
|
|
248 |
}
|
| 198 |
naveen |
249 |
|
| 1051 |
rajveer |
250 |
log.info("slideDefIDs:" + slideDefIDs);
|
|
|
251 |
|
| 242 |
naveen |
252 |
// Edit the entity from a specific slide
|
|
|
253 |
if(slideDefIDs != null && inputSlideDefID != 0L) {
|
|
|
254 |
|
|
|
255 |
// -2 : Not set
|
|
|
256 |
// -1 : Not found
|
|
|
257 |
int currentIndex = slideDefIDs.indexOf(
|
|
|
258 |
new Long(inputSlideDefID));
|
|
|
259 |
|
|
|
260 |
int nextIndex = -2;
|
| 499 |
rajveer |
261 |
if(currentIndex+1 != slideDefIDs.size()) {
|
| 242 |
naveen |
262 |
nextIndex = currentIndex + 1;
|
|
|
263 |
}
|
| 499 |
rajveer |
264 |
;
|
| 242 |
naveen |
265 |
int prevIndex = -2;
|
|
|
266 |
if(currentIndex != 0) {
|
|
|
267 |
prevIndex = currentIndex - 1;
|
|
|
268 |
}
|
| 499 |
rajveer |
269 |
|
| 242 |
naveen |
270 |
this.setNewCurrentSlideDefinitionID(
|
|
|
271 |
slideDefIDs.get(currentIndex).longValue());
|
|
|
272 |
if(nextIndex != -2) {
|
| 499 |
rajveer |
273 |
log.info("p7" + "---slidedefids:"+slideDefIDs+ "---nextIndex:"+nextIndex);
|
|
|
274 |
log.info("p7" + "---currentslide:"+currentIndex+ "---prevslide:"+prevIndex);
|
| 242 |
naveen |
275 |
this.setNewNextSlideDefinitionID(
|
|
|
276 |
slideDefIDs.get(nextIndex).longValue());
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
if(prevIndex != -2) {
|
|
|
280 |
this.setNewPrevSlideDefinitionID(
|
|
|
281 |
slideDefIDs.get(prevIndex).longValue());
|
|
|
282 |
}
|
| 198 |
naveen |
283 |
|
| 242 |
naveen |
284 |
// Current Slide Definition
|
|
|
285 |
this.expSlideDef = defs.getExpandedSlideDefinition(
|
|
|
286 |
inputSlideDefID);
|
|
|
287 |
// Current Slide Instance
|
|
|
288 |
this.expSlide = this.expEntity.getExpandedSlide(
|
|
|
289 |
inputSlideDefID);
|
|
|
290 |
return "editSlide";
|
|
|
291 |
}
|
| 162 |
naveen |
292 |
} catch (Exception e) {
|
| 208 |
naveen |
293 |
log.error(CreationUtils.getStackTrace(e));
|
|
|
294 |
this.setErrorString(CreationUtils.getStackTrace(e));
|
| 198 |
naveen |
295 |
return "fatal";
|
| 162 |
naveen |
296 |
}
|
|
|
297 |
|
|
|
298 |
return "edit";
|
|
|
299 |
}
|
| 198 |
naveen |
300 |
|
| 250 |
naveen |
301 |
/**
|
|
|
302 |
*
|
|
|
303 |
* @return
|
|
|
304 |
*/
|
| 198 |
naveen |
305 |
public String getUrl() {
|
|
|
306 |
return this.redirectURL;
|
|
|
307 |
}
|
| 250 |
naveen |
308 |
|
|
|
309 |
/**
|
|
|
310 |
*
|
|
|
311 |
* @return
|
|
|
312 |
*/
|
| 162 |
naveen |
313 |
// GET /entity/new
|
|
|
314 |
public String editNew() {
|
|
|
315 |
log.info("EntityController.editNew");
|
|
|
316 |
|
| 1051 |
rajveer |
317 |
if(!UserManager.getUserManager().canCreate(getUsername())){
|
|
|
318 |
addActionError("You do not have rights to create an entity.");
|
|
|
319 |
return "success";
|
|
|
320 |
}
|
|
|
321 |
|
| 162 |
naveen |
322 |
return "editNew";
|
|
|
323 |
}
|
| 250 |
naveen |
324 |
|
|
|
325 |
/**
|
|
|
326 |
*
|
|
|
327 |
* @return
|
|
|
328 |
*/
|
| 162 |
naveen |
329 |
// GET /entity/1
|
|
|
330 |
public String update() {
|
|
|
331 |
log.info("EntityController.update");
|
|
|
332 |
|
| 198 |
naveen |
333 |
long entityID = Long.parseLong(this.getId());
|
|
|
334 |
log.info("entityID:" + entityID);
|
|
|
335 |
|
| 1051 |
rajveer |
336 |
if(!UserManager.getUserManager().canEdit(getUsername(), entityID)){
|
|
|
337 |
return "success";
|
|
|
338 |
}
|
| 198 |
naveen |
339 |
|
|
|
340 |
try {
|
| 250 |
naveen |
341 |
this.expEntity = this.getExpandedEntity(entityID);
|
| 2607 |
rajveer |
342 |
|
| 242 |
naveen |
343 |
// Save and Go to slides selection page
|
|
|
344 |
if (this.reqparams.containsKey("slides")) {
|
| 2607 |
rajveer |
345 |
|
| 242 |
naveen |
346 |
Entity entity = this.expEntity.getEntity();
|
| 1051 |
rajveer |
347 |
|
| 242 |
naveen |
348 |
String categoryID = this.reqparams.get("category")[0];
|
|
|
349 |
|
|
|
350 |
entity.setCategoryID(Long.parseLong(categoryID));
|
|
|
351 |
|
| 2607 |
rajveer |
352 |
entity.setBrand((this.reqparams.get("brand")[0]).trim());
|
|
|
353 |
entity.setModelName((this.reqparams.get("modelname")[0]).trim());
|
|
|
354 |
entity.setModelNumber((this.reqparams.get("modelnumber")[0]).trim());
|
|
|
355 |
|
| 1152 |
rajveer |
356 |
EntityState entityState = CreationUtils.getEntityState(entity.getID());
|
|
|
357 |
entityState.setCategoryID(Long.parseLong(categoryID));
|
| 2607 |
rajveer |
358 |
entityState.setBrand((this.reqparams.get("brand")[0]).trim());
|
|
|
359 |
entityState.setModelName((this.reqparams.get("modelname")[0]).trim());
|
|
|
360 |
entityState.setModelNumber((this.reqparams.get("modelnumber")[0]).trim());
|
| 5906 |
rajveer |
361 |
updateTitleAndMetaDescription(entity);
|
| 1051 |
rajveer |
362 |
CreationUtils.updateEntity(entity);
|
| 1152 |
rajveer |
363 |
CreationUtils.updateEntityState(entityState);
|
| 242 |
naveen |
364 |
|
|
|
365 |
this.redirectURL = "/slides/" + this.getId() + "/edit";
|
|
|
366 |
return "redirect";
|
|
|
367 |
}
|
| 198 |
naveen |
368 |
|
| 213 |
naveen |
369 |
long currentSlideDefID = 0L;
|
|
|
370 |
long nextSlideDefID = 0L;
|
|
|
371 |
long prevSlideDefID = 0L;
|
| 250 |
naveen |
372 |
long gotoSlideDefID = 0L;
|
| 198 |
naveen |
373 |
|
| 213 |
naveen |
374 |
String[] currentslideDefIDStrings =
|
|
|
375 |
this.reqparams.get("currentslideDefID");
|
| 198 |
naveen |
376 |
|
| 213 |
naveen |
377 |
String[] nextslideDefIDStrings =
|
|
|
378 |
this.reqparams.get("nextslideDefID");
|
| 198 |
naveen |
379 |
|
| 213 |
naveen |
380 |
String[] prevslideDefIDStrings =
|
|
|
381 |
this.reqparams.get("prevslideDefID");
|
| 198 |
naveen |
382 |
|
| 250 |
naveen |
383 |
String[] gotoslideDefIDStrings =
|
|
|
384 |
this.reqparams.get("gotoslideDefID");
|
|
|
385 |
log.info("gotoslideDefIDStrings:" +
|
|
|
386 |
Arrays.toString(gotoslideDefIDStrings));
|
|
|
387 |
|
| 198 |
naveen |
388 |
// Current Slide ID
|
| 213 |
naveen |
389 |
if(currentslideDefIDStrings != null &&
|
|
|
390 |
currentslideDefIDStrings.length > 0) {
|
| 198 |
naveen |
391 |
try {
|
| 213 |
naveen |
392 |
currentSlideDefID = Long.parseLong(
|
|
|
393 |
currentslideDefIDStrings[0]);
|
| 198 |
naveen |
394 |
}
|
|
|
395 |
catch (NumberFormatException nfe) {}
|
|
|
396 |
}
|
|
|
397 |
|
|
|
398 |
// Next Slide ID
|
| 213 |
naveen |
399 |
if(nextslideDefIDStrings != null &&
|
|
|
400 |
nextslideDefIDStrings.length > 0) {
|
| 198 |
naveen |
401 |
try {
|
| 213 |
naveen |
402 |
nextSlideDefID = Long.parseLong(nextslideDefIDStrings[0]);
|
| 198 |
naveen |
403 |
}
|
|
|
404 |
catch (NumberFormatException nfe) {}
|
|
|
405 |
}
|
|
|
406 |
|
|
|
407 |
// Prev Slide ID
|
| 213 |
naveen |
408 |
if(prevslideDefIDStrings != null &&
|
|
|
409 |
prevslideDefIDStrings.length > 0) {
|
| 198 |
naveen |
410 |
try {
|
| 213 |
naveen |
411 |
prevSlideDefID = Long.parseLong(prevslideDefIDStrings[0]);
|
| 198 |
naveen |
412 |
}
|
|
|
413 |
catch (NumberFormatException nfe) {}
|
|
|
414 |
}
|
| 250 |
naveen |
415 |
|
|
|
416 |
// Go to Slide ID
|
|
|
417 |
if(gotoslideDefIDStrings != null &&
|
|
|
418 |
gotoslideDefIDStrings.length > 0) {
|
|
|
419 |
try {
|
|
|
420 |
gotoSlideDefID = Long.parseLong(gotoslideDefIDStrings[0]);
|
|
|
421 |
}
|
|
|
422 |
catch (NumberFormatException nfe) {}
|
|
|
423 |
}
|
|
|
424 |
|
| 213 |
naveen |
425 |
log.info("currentSlideDefID:" + currentSlideDefID);
|
|
|
426 |
log.info("nextSlideDefID:" + nextSlideDefID);
|
|
|
427 |
log.info("prevSlideDefID:" + prevSlideDefID);
|
| 250 |
naveen |
428 |
log.info("gotoSlideDefID:" + gotoSlideDefID);
|
| 198 |
naveen |
429 |
|
| 242 |
naveen |
430 |
|
| 198 |
naveen |
431 |
// Save on basic info page
|
| 213 |
naveen |
432 |
if (this.reqparams.containsKey("save") && currentSlideDefID == 0L) {
|
| 198 |
naveen |
433 |
log.info("Save");
|
|
|
434 |
|
|
|
435 |
Entity entity = this.expEntity.getEntity();
|
|
|
436 |
|
|
|
437 |
String categoryID = this.reqparams.get("category")[0];
|
|
|
438 |
|
|
|
439 |
entity.setCategoryID(Long.parseLong(categoryID));
|
| 2607 |
rajveer |
440 |
entity.setBrand((this.reqparams.get("brand")[0]).trim());
|
|
|
441 |
entity.setModelName((this.reqparams.get("modelname")[0]).trim());
|
|
|
442 |
entity.setModelNumber((this.reqparams.get("modelnumber")[0]).trim());
|
| 198 |
naveen |
443 |
|
| 1051 |
rajveer |
444 |
CreationUtils.updateEntity(entity);
|
| 198 |
naveen |
445 |
|
|
|
446 |
return "success";
|
|
|
447 |
}
|
|
|
448 |
|
| 250 |
naveen |
449 |
List<Long> slideIDs = this.getSlideSequence(entityID);
|
| 198 |
naveen |
450 |
log.info("slideIDs:"+slideIDs);
|
| 242 |
naveen |
451 |
if(slideIDs == null) {
|
|
|
452 |
this.setErrorString("Slides need to be picked first!");
|
|
|
453 |
return "fatal";
|
|
|
454 |
}
|
| 198 |
naveen |
455 |
|
| 1051 |
rajveer |
456 |
|
| 208 |
naveen |
457 |
boolean skip = false;
|
|
|
458 |
if(this.reqparams.containsKey("skipprev") ||
|
|
|
459 |
this.reqparams.containsKey("skipnext")) {
|
|
|
460 |
skip = true;
|
|
|
461 |
}
|
|
|
462 |
|
|
|
463 |
boolean next = this.reqparams.containsKey("skipnext") ||
|
|
|
464 |
this.reqparams.containsKey("next");
|
|
|
465 |
|
|
|
466 |
boolean prev = this.reqparams.containsKey("skipprev") ||
|
| 242 |
naveen |
467 |
this.reqparams.containsKey("prev");
|
| 208 |
naveen |
468 |
|
| 250 |
naveen |
469 |
boolean go = this.reqparams.containsKey("goto");
|
|
|
470 |
|
|
|
471 |
// Save or Next or Prev or Go - When editing a slide
|
| 198 |
naveen |
472 |
int currentSlideIndex = 0;
|
| 213 |
naveen |
473 |
currentSlideIndex = slideIDs.indexOf(new Long(currentSlideDefID));
|
| 208 |
naveen |
474 |
log.info("currentSlideIndex:" + currentSlideIndex);
|
| 198 |
naveen |
475 |
|
| 213 |
naveen |
476 |
if(!skip && currentSlideDefID != 0L) {
|
| 198 |
naveen |
477 |
Entity entity = this.expEntity.getEntity();
|
| 213 |
naveen |
478 |
// Create new instance and override existing
|
|
|
479 |
Slide currentSlide = this.createSlide(currentSlideDefID);
|
|
|
480 |
entity.addSlide(currentSlide);
|
| 1051 |
rajveer |
481 |
CreationUtils.updateEntity(entity);
|
| 198 |
naveen |
482 |
}
|
|
|
483 |
|
| 215 |
naveen |
484 |
// Skip will delete current slide from entity
|
|
|
485 |
else if(skip && currentSlideDefID != 0L) {
|
|
|
486 |
Entity entity = this.expEntity.getEntity();
|
|
|
487 |
entity.removeSlide(currentSlideDefID);
|
|
|
488 |
// Store
|
| 1051 |
rajveer |
489 |
CreationUtils.updateEntity(entity);
|
| 215 |
naveen |
490 |
}
|
| 2607 |
rajveer |
491 |
|
| 198 |
naveen |
492 |
boolean showAnotherSlide = false;
|
|
|
493 |
|
|
|
494 |
// -2 : Not set
|
|
|
495 |
// -1 : Not found
|
|
|
496 |
int newCurrentIndex = -2;
|
|
|
497 |
int newNextIndex = -2;
|
|
|
498 |
int newPrevIndex = -2;
|
|
|
499 |
|
|
|
500 |
// Next
|
| 213 |
naveen |
501 |
if(next && nextSlideDefID != 0L) {
|
| 198 |
naveen |
502 |
log.info("Next");
|
| 1051 |
rajveer |
503 |
log.info("p10");
|
| 198 |
naveen |
504 |
// Decide on next slide ID
|
| 213 |
naveen |
505 |
int nextSlideIndex = slideIDs.indexOf(new Long(nextSlideDefID));
|
| 198 |
naveen |
506 |
log.info("nextSlideIndex:"+nextSlideIndex);
|
|
|
507 |
|
|
|
508 |
// New Current
|
|
|
509 |
if (nextSlideIndex == -1) {
|
| 213 |
naveen |
510 |
this.setErrorString("Invalid Next slide ID " +
|
|
|
511 |
nextSlideDefID);
|
| 198 |
naveen |
512 |
return "fatal";
|
|
|
513 |
}
|
|
|
514 |
|
|
|
515 |
newCurrentIndex = nextSlideIndex;
|
|
|
516 |
|
|
|
517 |
// New Next
|
|
|
518 |
if (newCurrentIndex != slideIDs.size()-1) {
|
|
|
519 |
newNextIndex = newCurrentIndex + 1;
|
|
|
520 |
}
|
|
|
521 |
|
|
|
522 |
// New Prev.
|
| 213 |
naveen |
523 |
if(currentSlideDefID != 0L) {
|
| 198 |
naveen |
524 |
newPrevIndex = currentSlideIndex;
|
|
|
525 |
}
|
|
|
526 |
|
|
|
527 |
showAnotherSlide = true;
|
|
|
528 |
}
|
|
|
529 |
|
|
|
530 |
// Prev
|
| 213 |
naveen |
531 |
if(prev && prevSlideDefID != 0L) {
|
| 198 |
naveen |
532 |
log.info("Prev");
|
| 1051 |
rajveer |
533 |
log.info("p11");
|
| 198 |
naveen |
534 |
// Decide on prev slide ID
|
| 213 |
naveen |
535 |
int prevSlideIndex = slideIDs.indexOf(new Long(prevSlideDefID));
|
| 198 |
naveen |
536 |
log.info("prevSlideIndex:" + prevSlideIndex);
|
|
|
537 |
|
|
|
538 |
if (prevSlideIndex == -1) {
|
| 213 |
naveen |
539 |
this.setErrorString("Invalid Prev slide ID " +
|
|
|
540 |
prevSlideDefID);
|
| 198 |
naveen |
541 |
return "fatal";
|
|
|
542 |
}
|
|
|
543 |
|
|
|
544 |
// New Next
|
| 213 |
naveen |
545 |
if(currentSlideDefID != 0L) {
|
| 198 |
naveen |
546 |
newNextIndex = currentSlideIndex;
|
|
|
547 |
}
|
|
|
548 |
|
|
|
549 |
// New Current
|
|
|
550 |
newCurrentIndex = prevSlideIndex;
|
|
|
551 |
|
|
|
552 |
// New Prev.
|
|
|
553 |
if (newCurrentIndex != 0) {
|
|
|
554 |
newPrevIndex = newCurrentIndex - 1;
|
|
|
555 |
}
|
|
|
556 |
|
|
|
557 |
showAnotherSlide = true;
|
|
|
558 |
}
|
|
|
559 |
|
| 250 |
naveen |
560 |
// Go to
|
|
|
561 |
if(go && gotoSlideDefID != 0) {
|
|
|
562 |
log.info("Goto");
|
| 1051 |
rajveer |
563 |
log.info("p12");
|
| 250 |
naveen |
564 |
int gotoSlideIndex = slideIDs.indexOf(new Long(gotoSlideDefID));
|
|
|
565 |
log.info("gotoSlideIndex:" + gotoSlideIndex);
|
|
|
566 |
|
|
|
567 |
if (gotoSlideIndex == -1) {
|
|
|
568 |
this.setErrorString("Invalid Go to slide ID " +
|
|
|
569 |
gotoSlideDefID);
|
|
|
570 |
return "fatal";
|
|
|
571 |
}
|
|
|
572 |
|
|
|
573 |
// New Next
|
|
|
574 |
if(gotoSlideIndex != slideIDs.size()-1) {
|
|
|
575 |
newNextIndex = gotoSlideIndex + 1;
|
|
|
576 |
}
|
|
|
577 |
|
|
|
578 |
// New Current
|
|
|
579 |
newCurrentIndex = gotoSlideIndex;
|
|
|
580 |
|
|
|
581 |
// New Prev.
|
|
|
582 |
if (gotoSlideIndex != 0) {
|
|
|
583 |
newPrevIndex = gotoSlideIndex - 1;
|
|
|
584 |
}
|
|
|
585 |
|
|
|
586 |
showAnotherSlide = true;
|
|
|
587 |
}
|
|
|
588 |
|
| 198 |
naveen |
589 |
if(showAnotherSlide) {
|
| 213 |
naveen |
590 |
log.info("newCurrentIndex:" + newCurrentIndex);
|
|
|
591 |
log.info("newNextIndex:" + newNextIndex);
|
|
|
592 |
log.info("newPrevIndex:" + newPrevIndex);
|
| 198 |
naveen |
593 |
|
| 1051 |
rajveer |
594 |
log.info("p13");
|
|
|
595 |
|
| 198 |
naveen |
596 |
if(newCurrentIndex != -2) {
|
|
|
597 |
this.setNewCurrentSlideDefinitionID(
|
|
|
598 |
slideIDs.get(newCurrentIndex).longValue());
|
|
|
599 |
}
|
|
|
600 |
|
|
|
601 |
if(newNextIndex != -2) {
|
|
|
602 |
this.setNewNextSlideDefinitionID(
|
|
|
603 |
slideIDs.get(newNextIndex).longValue());
|
|
|
604 |
}
|
|
|
605 |
|
|
|
606 |
if(newPrevIndex != -2) {
|
|
|
607 |
this.setNewPrevSlideDefinitionID(
|
|
|
608 |
slideIDs.get(newPrevIndex).longValue());
|
|
|
609 |
}
|
| 242 |
naveen |
610 |
|
|
|
611 |
long newCurrentSlideDefID =
|
|
|
612 |
this.getNewCurrentSlideDefinitionID();
|
|
|
613 |
log.info("newCurrentSlideDefID:" + newCurrentSlideDefID);
|
| 198 |
naveen |
614 |
|
|
|
615 |
// Current Slide Definition
|
|
|
616 |
this.expSlideDef = defs.getExpandedSlideDefinition(
|
| 242 |
naveen |
617 |
newCurrentSlideDefID);
|
| 198 |
naveen |
618 |
|
|
|
619 |
// Current Slide Instance
|
|
|
620 |
this.expSlide = this.expEntity.getExpandedSlide(
|
| 242 |
naveen |
621 |
newCurrentSlideDefID);
|
| 198 |
naveen |
622 |
|
| 242 |
naveen |
623 |
log.info("this.expSlide is null: " + (this.expSlide == null));
|
|
|
624 |
|
| 198 |
naveen |
625 |
return "editSlide";
|
|
|
626 |
}
|
|
|
627 |
}
|
|
|
628 |
catch (Exception e) {
|
| 208 |
naveen |
629 |
log.error(CreationUtils.getStackTrace(e));
|
|
|
630 |
this.setErrorString(CreationUtils.getStackTrace(e));
|
| 198 |
naveen |
631 |
return "fatal";
|
|
|
632 |
}
|
|
|
633 |
|
|
|
634 |
return "success";
|
| 162 |
naveen |
635 |
}
|
| 213 |
naveen |
636 |
|
| 5906 |
rajveer |
637 |
private void updateTitleAndMetaDescription(Entity entity) {
|
| 5760 |
amit.gupta |
638 |
Slide summarySlide = entity.getSlide(130054l);
|
|
|
639 |
if (summarySlide != null){
|
|
|
640 |
List<Feature> features = summarySlide.getFeatures();
|
|
|
641 |
if(features != null){
|
|
|
642 |
for(Feature f : features) {
|
|
|
643 |
if(f.getFeatureDefinitionID()==120132l){
|
|
|
644 |
if(f.getBullets() == null){
|
|
|
645 |
f.setBullets(new ArrayList<Bullet>());
|
|
|
646 |
}else {
|
|
|
647 |
f.getBullets().clear();
|
|
|
648 |
}
|
| 5914 |
amit.gupta |
649 |
Bullet titleBullet = new Bullet(new PrimitiveDataObject(getTitle()));
|
| 5760 |
amit.gupta |
650 |
f.getBullets().add(titleBullet);
|
|
|
651 |
}
|
|
|
652 |
else if(f.getFeatureDefinitionID()==120133l){
|
|
|
653 |
if(f.getBullets() == null){
|
|
|
654 |
f.setBullets(new ArrayList<Bullet>());
|
|
|
655 |
}else {
|
|
|
656 |
f.getBullets().clear();
|
|
|
657 |
}
|
| 5914 |
amit.gupta |
658 |
Bullet metaDescBullet = new Bullet(new PrimitiveDataObject(getMetaDescription()));
|
| 5760 |
amit.gupta |
659 |
f.getBullets().add(metaDescBullet);
|
|
|
660 |
}
|
|
|
661 |
}
|
|
|
662 |
}
|
|
|
663 |
}
|
|
|
664 |
}
|
|
|
665 |
|
| 5914 |
amit.gupta |
666 |
public String getTitle(){
|
| 5760 |
amit.gupta |
667 |
String brand = entity.getBrand();
|
|
|
668 |
String modelName = entity.getModelName();
|
|
|
669 |
String modelNumber = entity.getModelNumber();
|
|
|
670 |
String titleString = "";
|
|
|
671 |
if(StringUtils.isEmpty(modelName)){
|
|
|
672 |
titleString = brand + " " + modelNumber + " Price in India | Specifications, Features and Reviews";
|
|
|
673 |
}else {
|
|
|
674 |
titleString = brand + " " + modelName + " Price in India | " + modelNumber + " Specifications, Features and Reviews";
|
|
|
675 |
}
|
|
|
676 |
return titleString;
|
|
|
677 |
}
|
|
|
678 |
|
| 5914 |
amit.gupta |
679 |
public String getMetaDescription(){
|
| 6041 |
amit.gupta |
680 |
Category cat = defs.getCategory(entity.getCategoryID());
|
|
|
681 |
Category parentCategory = cat.getParentCategory();
|
| 5760 |
amit.gupta |
682 |
String categoryName = parentCategory.getLabel();
|
|
|
683 |
if (parentCategory.getID()== Utils.MOBILE_ACCESSORIES_CATEGORY){
|
| 6041 |
amit.gupta |
684 |
categoryName = cat.getLabel();
|
| 5760 |
amit.gupta |
685 |
}
|
|
|
686 |
String template = "Buy {0} {1} {2} at $minPriceItem.getSellingPrice(). All {3} are 100% Original and carry full Manufacturers Warranty since we procure directly from the Brand. Free Next Day Delivery.";
|
|
|
687 |
return MessageFormat.format(template, entity.getBrand(), entity.getModelName(), entity.getModelNumber(), categoryName.toLowerCase());
|
|
|
688 |
}
|
|
|
689 |
|
|
|
690 |
/**
|
| 201 |
naveen |
691 |
*
|
| 250 |
naveen |
692 |
* @param entityID
|
|
|
693 |
* @return
|
|
|
694 |
* @throws Exception
|
|
|
695 |
*/
|
|
|
696 |
public long getBorrowedCategoryID(long slideDefID) throws Exception {
|
|
|
697 |
long entityID = Long.parseLong(this.getId());
|
| 1051 |
rajveer |
698 |
entity = CreationUtils.getEntity(entityID);
|
| 250 |
naveen |
699 |
Long entityCatID = new Long(entity.getCategoryID());
|
|
|
700 |
|
|
|
701 |
Map<Long, List<Long>> catSlides = this.getRawSlideSequence(entityID);
|
|
|
702 |
|
|
|
703 |
Long lSlideDefID = new Long(slideDefID);
|
|
|
704 |
if(catSlides != null) {
|
|
|
705 |
for(Long catID : catSlides.keySet()) {
|
|
|
706 |
List<Long> slideDefIDs = catSlides.get(catID);
|
|
|
707 |
if(slideDefIDs.contains(lSlideDefID) &&
|
|
|
708 |
!catID.equals(entityCatID)) {
|
|
|
709 |
return catID.longValue();
|
|
|
710 |
}
|
|
|
711 |
}
|
|
|
712 |
}
|
|
|
713 |
|
|
|
714 |
return 0L;
|
|
|
715 |
}
|
|
|
716 |
|
|
|
717 |
/**
|
|
|
718 |
*
|
|
|
719 |
* @param entityID
|
|
|
720 |
* @return
|
|
|
721 |
* @throws Exception
|
|
|
722 |
*/
|
|
|
723 |
private List<Long> getSlideSequence(long entityID) throws Exception {
|
| 1051 |
rajveer |
724 |
//this.catSlides = this.getRawSlideSequence(entityID);
|
|
|
725 |
//return CreationUtils.getSlideSequence(this.catSlides);
|
|
|
726 |
return entity.getSlideSequence();
|
| 250 |
naveen |
727 |
}
|
|
|
728 |
|
|
|
729 |
/**
|
|
|
730 |
*
|
|
|
731 |
* @param entityID
|
|
|
732 |
* @return
|
|
|
733 |
* @throws Exception
|
|
|
734 |
*/
|
|
|
735 |
private Map<Long, List<Long>> getRawSlideSequence(long entityID)
|
|
|
736 |
throws Exception {
|
|
|
737 |
if(this.catSlides == null) {
|
| 1051 |
rajveer |
738 |
this.catSlides = defs.getCategorySlideSequence();
|
| 250 |
naveen |
739 |
}
|
|
|
740 |
|
|
|
741 |
return this.catSlides;
|
|
|
742 |
}
|
|
|
743 |
|
|
|
744 |
|
|
|
745 |
/**
|
|
|
746 |
*
|
| 213 |
naveen |
747 |
* @param slideDefID
|
|
|
748 |
* @return
|
|
|
749 |
* @throws Exception
|
|
|
750 |
*/
|
|
|
751 |
private Slide createSlide(long slideDefID) throws Exception {
|
|
|
752 |
Slide slide = new Slide(slideDefID);
|
|
|
753 |
|
| 1176 |
rajveer |
754 |
// long borrowedCategoryID = this.getBorrowedCategoryID(slideDefID);
|
|
|
755 |
// log.info("borrowedCategoryID:" + borrowedCategoryID);
|
|
|
756 |
//
|
|
|
757 |
// if(borrowedCategoryID != 0L) {
|
|
|
758 |
// slide.setBorrowedCategoryID(borrowedCategoryID);
|
|
|
759 |
// }
|
| 250 |
naveen |
760 |
|
| 213 |
naveen |
761 |
// Slide free-form content
|
|
|
762 |
FreeformContent slideFFC = this.getFreeformContent(
|
|
|
763 |
"slide_" + slideDefID);
|
|
|
764 |
|
|
|
765 |
log.info("slideFFC:" + slideFFC);
|
|
|
766 |
|
|
|
767 |
slide.setFreeformContent(slideFFC);
|
|
|
768 |
//log.info("currentSlide:" + currentSlide);
|
|
|
769 |
|
|
|
770 |
// Collect Feature bullets
|
|
|
771 |
List<Feature> features = this.createFeatures(slide);
|
|
|
772 |
log.info("features:" + features);
|
|
|
773 |
|
|
|
774 |
slide.setFeatures(features);
|
|
|
775 |
|
|
|
776 |
// Collect children slides
|
| 1051 |
rajveer |
777 |
SlideDefinition slideDef = this.defs.getSlideDefinition(slideDefID);
|
| 213 |
naveen |
778 |
|
| 4959 |
amit.gupta |
779 |
List<ChildSlideDefinition> childrenSlides = slideDef.getChildSlideDefinitions();
|
|
|
780 |
if(childrenSlides != null) {
|
|
|
781 |
List<Slide> childSlides = new ArrayList<Slide>();
|
|
|
782 |
for (ChildSlideDefinition childSlideDef : childrenSlides) {
|
|
|
783 |
// Ignore skipped featured
|
|
|
784 |
String[] skipvalue =
|
|
|
785 |
this.reqparams.get(childSlideDef.getId() + "_skip");
|
|
|
786 |
log.info("skipvalue for " + childSlideDef.getId() + " :" + Arrays.toString(skipvalue));
|
|
|
787 |
|
|
|
788 |
if(skipvalue != null && skipvalue.length > 0 &&
|
|
|
789 |
skipvalue[0].equals("on")) {
|
|
|
790 |
continue;
|
|
|
791 |
}
|
|
|
792 |
|
|
|
793 |
Slide childSlide = this.createSlide(childSlideDef.getId());
|
| 213 |
naveen |
794 |
if(childSlide != null) {
|
| 4959 |
amit.gupta |
795 |
childSlides.add(childSlide);
|
| 213 |
naveen |
796 |
}
|
|
|
797 |
}
|
|
|
798 |
|
| 4959 |
amit.gupta |
799 |
slide.setChildrenSlides(childSlides);
|
| 213 |
naveen |
800 |
}
|
|
|
801 |
|
|
|
802 |
return slide;
|
|
|
803 |
}
|
|
|
804 |
|
|
|
805 |
/**
|
|
|
806 |
*
|
| 201 |
naveen |
807 |
* @param slide
|
|
|
808 |
* @return
|
|
|
809 |
* @throws Exception
|
|
|
810 |
*/
|
|
|
811 |
private List<Feature> createFeatures(Slide slide) throws Exception {
|
|
|
812 |
|
|
|
813 |
long slideDefID = slide.getSlideDefinitionID();
|
|
|
814 |
SlideDefinition slideDef = defs.getSlideDefinition(slideDefID);
|
|
|
815 |
|
|
|
816 |
List<SlideFeatureDefinition> slideFeatureDefs =
|
|
|
817 |
slideDef.getSlideFeatureDefinitions();
|
|
|
818 |
|
|
|
819 |
List<Feature> features = new ArrayList<Feature>();
|
|
|
820 |
for(SlideFeatureDefinition slideFeatureDef : slideFeatureDefs) {
|
|
|
821 |
long featureDefinitionID = slideFeatureDef.getFeatureDefintionID();
|
| 215 |
naveen |
822 |
log.info("featureDefinitionID:" + featureDefinitionID);
|
| 204 |
naveen |
823 |
|
| 215 |
naveen |
824 |
// Ignore skipped featured
|
|
|
825 |
String[] skipvalue =
|
|
|
826 |
this.reqparams.get(featureDefinitionID + "_skip");
|
|
|
827 |
log.info("skipvalue:" + Arrays.toString(skipvalue));
|
|
|
828 |
|
|
|
829 |
if(skipvalue != null && skipvalue.length > 0 &&
|
|
|
830 |
skipvalue[0].equals("on")) {
|
|
|
831 |
continue;
|
|
|
832 |
}
|
|
|
833 |
|
| 201 |
naveen |
834 |
String featureDefIDString =
|
|
|
835 |
new Long(featureDefinitionID).toString();
|
|
|
836 |
|
|
|
837 |
Feature feature = new Feature(featureDefinitionID);
|
| 310 |
rajveer |
838 |
|
| 201 |
naveen |
839 |
FeatureDefinition featureDef = defs.getFeatureDefinition(
|
|
|
840 |
featureDefinitionID);
|
| 204 |
naveen |
841 |
log.info("featureDef:" + featureDef);
|
| 201 |
naveen |
842 |
|
|
|
843 |
ExpandedFeatureDefinition expFeatureDef =
|
|
|
844 |
new ExpandedFeatureDefinition(featureDef);
|
|
|
845 |
|
|
|
846 |
ExpandedBulletDefinition expBulletDef =
|
|
|
847 |
expFeatureDef.getExpandedBulletDefinition();
|
|
|
848 |
|
| 310 |
rajveer |
849 |
boolean isBlank = false;
|
|
|
850 |
|
|
|
851 |
// Check if feature has no bullets
|
|
|
852 |
// Composite
|
|
|
853 |
if(expBulletDef.isComposite()) {
|
|
|
854 |
CompositeDefinition compositeDef = (CompositeDefinition)
|
|
|
855 |
expBulletDef.getDatatypeDefinition();
|
|
|
856 |
|
|
|
857 |
List<CompositePartDefinition> compositeParts =
|
|
|
858 |
compositeDef.getCompositePartDefinitions();
|
|
|
859 |
|
|
|
860 |
boolean allPartsBlank = true;
|
|
|
861 |
for(int j=0;j<compositeParts.size();j++) {
|
|
|
862 |
String[] partValues = this.reqparams.get(
|
|
|
863 |
featureDefIDString + "_" + (j + 1));
|
|
|
864 |
|
|
|
865 |
if(partValues != null && partValues.length > 0) {
|
|
|
866 |
allPartsBlank = false;
|
|
|
867 |
}
|
|
|
868 |
}
|
|
|
869 |
|
|
|
870 |
isBlank = allPartsBlank;
|
|
|
871 |
}
|
|
|
872 |
|
|
|
873 |
// Enumerated and Primitive
|
|
|
874 |
else {
|
|
|
875 |
String[] bulletValues = this.reqparams.get(featureDefIDString);
|
|
|
876 |
if(bulletValues == null || bulletValues.length == 0) {
|
|
|
877 |
isBlank = true;
|
|
|
878 |
}
|
|
|
879 |
}
|
|
|
880 |
|
|
|
881 |
// Has no bullets
|
|
|
882 |
if(isBlank) {
|
| 403 |
rajveer |
883 |
|
|
|
884 |
// Mandatory
|
|
|
885 |
// or optional/recommended but allows blanck and not skipped
|
| 310 |
rajveer |
886 |
if(slideFeatureDef.getEditorialImportance() ==
|
| 480 |
rajveer |
887 |
EditorialImportance.MANDATORY || expFeatureDef.allowsBlank()) {
|
|
|
888 |
// FFC
|
|
|
889 |
FreeformContent featureFFC =
|
|
|
890 |
this.getFreeformContent(featureDefIDString);
|
|
|
891 |
|
|
|
892 |
feature.setFreeformContent(featureFFC);
|
|
|
893 |
|
| 310 |
rajveer |
894 |
features.add(feature);
|
|
|
895 |
}
|
|
|
896 |
|
|
|
897 |
continue;
|
|
|
898 |
}
|
|
|
899 |
|
|
|
900 |
// Bullets
|
|
|
901 |
List<Bullet> bullets = new ArrayList<Bullet>();
|
|
|
902 |
|
| 206 |
naveen |
903 |
// Collect unit
|
|
|
904 |
String[] unitIDs = this.reqparams.get(featureDefIDString + "_unit");
|
|
|
905 |
long unitID = 0L;
|
|
|
906 |
if(unitIDs != null && unitIDs.length > 0) {
|
|
|
907 |
unitID = Long.parseLong(unitIDs[0]);
|
|
|
908 |
}
|
|
|
909 |
|
| 201 |
naveen |
910 |
// Composite
|
|
|
911 |
if(expBulletDef.isComposite()) {
|
| 204 |
naveen |
912 |
log.info("Composite");
|
| 201 |
naveen |
913 |
|
| 204 |
naveen |
914 |
CompositeDataObject compositeDataObject =
|
|
|
915 |
new CompositeDataObject();
|
|
|
916 |
|
|
|
917 |
CompositeDefinition compositeDef =
|
|
|
918 |
(CompositeDefinition)expBulletDef.getDatatypeDefinition();
|
|
|
919 |
|
|
|
920 |
List<CompositePartDefinition> compositeParts =
|
|
|
921 |
compositeDef.getCompositePartDefinitions();
|
|
|
922 |
|
|
|
923 |
for(int j=0;j<compositeParts.size();j++) {
|
|
|
924 |
String[] partValues = this.reqparams.get(
|
| 208 |
naveen |
925 |
featureDefIDString + "_" + (j + 1));
|
| 204 |
naveen |
926 |
|
|
|
927 |
if(partValues != null && partValues.length > 0) {
|
|
|
928 |
compositeDataObject.addPrimitiveDataObject(
|
|
|
929 |
new PrimitiveDataObject(partValues[0]));
|
|
|
930 |
}
|
|
|
931 |
}
|
|
|
932 |
|
|
|
933 |
Bullet bullet = new Bullet(compositeDataObject);
|
|
|
934 |
|
| 206 |
naveen |
935 |
if(unitID != 0L) {
|
|
|
936 |
bullet.setUnitID(unitID);
|
|
|
937 |
}
|
|
|
938 |
|
| 204 |
naveen |
939 |
bullets.add(bullet);
|
| 201 |
naveen |
940 |
}
|
|
|
941 |
|
|
|
942 |
// Enumerated
|
|
|
943 |
else if(expBulletDef.isEnumerated()) {
|
| 204 |
naveen |
944 |
log.info("Enumerated");
|
| 310 |
rajveer |
945 |
|
| 204 |
naveen |
946 |
String[] bulletValues = this.reqparams.get(featureDefIDString);
|
|
|
947 |
log.info("bulletValues:" + Arrays.toString(bulletValues));
|
| 206 |
naveen |
948 |
|
| 204 |
naveen |
949 |
|
| 206 |
naveen |
950 |
for(int i=0;i<bulletValues.length;i++) {
|
|
|
951 |
EnumDataObject enumDataObject =
|
|
|
952 |
new EnumDataObject(Long.parseLong(bulletValues[i]));
|
|
|
953 |
|
|
|
954 |
Bullet bullet = new Bullet(enumDataObject);
|
|
|
955 |
|
|
|
956 |
if(unitID != 0L) {
|
|
|
957 |
bullet.setUnitID(unitID);
|
|
|
958 |
}
|
|
|
959 |
|
|
|
960 |
bullets.add(bullet);
|
|
|
961 |
}
|
| 201 |
naveen |
962 |
}
|
|
|
963 |
|
|
|
964 |
// Primitive
|
|
|
965 |
else {
|
| 204 |
naveen |
966 |
log.info("Primitive");
|
| 310 |
rajveer |
967 |
|
| 204 |
naveen |
968 |
String[] bulletValues = this.reqparams.get(featureDefIDString);
|
|
|
969 |
log.info("bulletValues:" + Arrays.toString(bulletValues));
|
|
|
970 |
|
| 206 |
naveen |
971 |
for(int i=0;i<bulletValues.length;i++) {
|
|
|
972 |
Bullet bullet = new Bullet(
|
|
|
973 |
new PrimitiveDataObject(bulletValues[i]));
|
|
|
974 |
|
|
|
975 |
if(unitID != 0L) {
|
|
|
976 |
bullet.setUnitID(unitID);
|
|
|
977 |
}
|
|
|
978 |
|
|
|
979 |
bullets.add(bullet);
|
|
|
980 |
}
|
| 201 |
naveen |
981 |
}
|
|
|
982 |
|
|
|
983 |
feature.setBullets(bullets);
|
|
|
984 |
|
|
|
985 |
// FFC
|
|
|
986 |
FreeformContent featureFFC =
|
|
|
987 |
this.getFreeformContent(featureDefIDString);
|
|
|
988 |
|
|
|
989 |
feature.setFreeformContent(featureFFC);
|
|
|
990 |
|
|
|
991 |
features.add(feature);
|
|
|
992 |
}
|
|
|
993 |
|
|
|
994 |
return features;
|
|
|
995 |
}
|
|
|
996 |
|
| 242 |
naveen |
997 |
// DELETE /entity/1000001
|
|
|
998 |
/**
|
|
|
999 |
*
|
|
|
1000 |
*/
|
|
|
1001 |
public String destroy() {
|
| 250 |
naveen |
1002 |
log.info("#### EntityController.destroy ####");
|
| 242 |
naveen |
1003 |
|
|
|
1004 |
long entityID = Long.parseLong(this.getId());
|
|
|
1005 |
log.info("entityID:" + entityID);
|
|
|
1006 |
|
| 1051 |
rajveer |
1007 |
if(!UserManager.getUserManager().canDelete(getUsername(), entityID)){
|
|
|
1008 |
addActionError("You do not have rights to delete an entity");
|
|
|
1009 |
return "success";
|
|
|
1010 |
}
|
|
|
1011 |
|
| 242 |
naveen |
1012 |
// Store
|
|
|
1013 |
try {
|
| 250 |
naveen |
1014 |
CreationUtils.deleteEntity(entityID);
|
| 242 |
naveen |
1015 |
} catch (Exception e) {
|
|
|
1016 |
log.error(CreationUtils.getStackTrace(e));
|
|
|
1017 |
this.setErrorString(CreationUtils.getStackTrace(e));
|
|
|
1018 |
return "fatal";
|
|
|
1019 |
}
|
|
|
1020 |
addActionMessage("Entity deleted successfully");
|
|
|
1021 |
return "success";
|
|
|
1022 |
}
|
| 201 |
naveen |
1023 |
/**
|
|
|
1024 |
*
|
|
|
1025 |
* @param ID
|
|
|
1026 |
* @return
|
|
|
1027 |
*/
|
|
|
1028 |
private FreeformContent getFreeformContent(String ID) {
|
| 450 |
rajveer |
1029 |
|
|
|
1030 |
|
| 201 |
naveen |
1031 |
FreeformContent ffc = new FreeformContent();
|
|
|
1032 |
String[] ffts = this.reqparams.get(ID + "_fft");
|
|
|
1033 |
if(ffts != null) {
|
|
|
1034 |
ffc.setFreeformTexts(Arrays.asList(ffts));
|
|
|
1035 |
}
|
|
|
1036 |
|
| 450 |
rajveer |
1037 |
System.out.println("String is " + ID);
|
|
|
1038 |
|
|
|
1039 |
StringTokenizer tokenizer = new StringTokenizer(ID,"_");
|
|
|
1040 |
if(tokenizer.nextToken().compareTo("slide") == 0 ){
|
|
|
1041 |
long slideId = Long.parseLong(tokenizer.nextToken());
|
|
|
1042 |
FreeformContent old_ffc = null;
|
|
|
1043 |
if(this.entity.getSlide(slideId) != null){
|
|
|
1044 |
old_ffc = this.entity.getSlide(slideId).getFreeformContent();
|
|
|
1045 |
if(old_ffc != null){
|
| 1051 |
rajveer |
1046 |
ffc.setMedias(old_ffc.getMedias());
|
| 450 |
rajveer |
1047 |
}
|
|
|
1048 |
}
|
|
|
1049 |
}
|
| 201 |
naveen |
1050 |
|
|
|
1051 |
|
| 450 |
rajveer |
1052 |
// String[] imgRefs = this.reqparams.get(ID + "_image_references");
|
|
|
1053 |
// if(imgRefs != null) {
|
|
|
1054 |
// ffc.setMedia("image", Arrays.asList(imgRefs));
|
|
|
1055 |
// }
|
|
|
1056 |
//
|
|
|
1057 |
// String[] youtubeRefs =
|
|
|
1058 |
// this.reqparams.get(ID + "_youtube_references");
|
|
|
1059 |
// if(youtubeRefs != null) {
|
|
|
1060 |
// ffc.setMedia("youtube", Arrays.asList(youtubeRefs));
|
|
|
1061 |
// }
|
|
|
1062 |
|
| 201 |
naveen |
1063 |
log.info("ffc:" + ffc);
|
|
|
1064 |
return ffc;
|
|
|
1065 |
}
|
| 213 |
naveen |
1066 |
|
|
|
1067 |
|
|
|
1068 |
/**
|
|
|
1069 |
*
|
|
|
1070 |
* @param slideDefinitionID
|
|
|
1071 |
* @return
|
|
|
1072 |
*/
|
|
|
1073 |
public ExpandedSlide getChildSlide(long slideDefinitionID) {
|
| 242 |
naveen |
1074 |
if(this.expSlide == null) {
|
|
|
1075 |
return null;
|
|
|
1076 |
}
|
|
|
1077 |
|
| 213 |
naveen |
1078 |
return this.getChildSlide(this.expSlide, slideDefinitionID);
|
|
|
1079 |
}
|
|
|
1080 |
|
|
|
1081 |
|
|
|
1082 |
/**
|
|
|
1083 |
*
|
|
|
1084 |
* @param expSlide
|
|
|
1085 |
* @param slideDefinitionID
|
|
|
1086 |
* @return
|
|
|
1087 |
*/
|
|
|
1088 |
public ExpandedSlide getChildSlide(ExpandedSlide expSlide,
|
|
|
1089 |
long slideDefinitionID) {
|
|
|
1090 |
|
|
|
1091 |
List<ExpandedSlide> childrenSlides =
|
|
|
1092 |
expSlide.getExpandedChildrenSlides();
|
|
|
1093 |
|
|
|
1094 |
ExpandedSlide resultSlide = null;
|
|
|
1095 |
|
|
|
1096 |
if(childrenSlides != null) {
|
|
|
1097 |
for(ExpandedSlide childSlide : childrenSlides) {
|
|
|
1098 |
if(childSlide.getSlideDefinitionID() == slideDefinitionID) {
|
|
|
1099 |
return childSlide;
|
|
|
1100 |
}
|
|
|
1101 |
|
|
|
1102 |
resultSlide = this.getChildSlide(childSlide, slideDefinitionID);
|
|
|
1103 |
if(resultSlide == null) {
|
|
|
1104 |
continue;
|
|
|
1105 |
}
|
|
|
1106 |
else {
|
|
|
1107 |
break;
|
|
|
1108 |
}
|
|
|
1109 |
}
|
|
|
1110 |
}
|
|
|
1111 |
|
|
|
1112 |
return resultSlide;
|
|
|
1113 |
}
|
| 201 |
naveen |
1114 |
|
|
|
1115 |
/**
|
| 162 |
naveen |
1116 |
* @return the entities
|
|
|
1117 |
*/
|
| 516 |
rajveer |
1118 |
public Map<Long, List<Entity>> getEntitiesByCategory() {
|
|
|
1119 |
return catEntities;
|
|
|
1120 |
}
|
|
|
1121 |
|
| 1051 |
rajveer |
1122 |
/**
|
| 739 |
chandransh |
1123 |
* Inquires about items in the IN_PROCESS state with the Catalog service and
|
|
|
1124 |
* creates those entities which do not exist in the CMS already.
|
|
|
1125 |
*
|
|
|
1126 |
* @return A List of entities fetched from the catalog.
|
|
|
1127 |
*/
|
|
|
1128 |
private void createEntitiesForItemsInProcess(){
|
| 6894 |
amit.gupta |
1129 |
//Do once in every hour
|
| 7099 |
amit.gupta |
1130 |
if (new Date().getTime() - lastEntityCreation.getTime() > 20*60*1000) {
|
| 6894 |
amit.gupta |
1131 |
try {
|
|
|
1132 |
CatalogClient csc = new CatalogClient();
|
|
|
1133 |
in.shop2020.model.v1.catalog.CatalogService.Client iclient = csc.getClient();
|
|
|
1134 |
List<Item> items = iclient.getAllItemsByStatus(status.IN_PROCESS);
|
|
|
1135 |
for(Item item: items){
|
|
|
1136 |
long entityID = item.getCatalogItemId();
|
|
|
1137 |
if(!this.entitiesState.containsKey(entityID)){
|
|
|
1138 |
log.info("#### Going to add the entity with id: ####" + entityID);
|
|
|
1139 |
Entity entity = new Entity(entityID, -1);
|
|
|
1140 |
entity.setBrand(item.getBrand());
|
|
|
1141 |
entity.setModelNumber(item.getModelNumber() + " (" + item.getProductGroup() + ")");
|
|
|
1142 |
entity.setModelName((item.getModelName()==null) ? "" : item.getModelName());
|
|
|
1143 |
EntityState entityState = new EntityState(entityID, -1, UserManager.getUserManager().getAdminName());
|
|
|
1144 |
entityState.setBrand(item.getBrand());
|
|
|
1145 |
entityState.setModelNumber(item.getModelNumber() + " (" + item.getProductGroup() + ")");
|
|
|
1146 |
entityState.setModelName((item.getModelName()==null) ? "" : item.getModelName());
|
|
|
1147 |
CreationUtils.createEntity(entity, entityState);
|
|
|
1148 |
}else
|
|
|
1149 |
log.info("###Everything went all right and we got an entity");
|
|
|
1150 |
}
|
|
|
1151 |
} catch (Exception e) {
|
|
|
1152 |
e.printStackTrace();
|
| 739 |
chandransh |
1153 |
}
|
| 6894 |
amit.gupta |
1154 |
lastEntityCreation = new Date();
|
| 739 |
chandransh |
1155 |
}
|
|
|
1156 |
}
|
| 250 |
naveen |
1157 |
|
| 162 |
naveen |
1158 |
/**
|
|
|
1159 |
* @return the entities
|
|
|
1160 |
*/
|
|
|
1161 |
public ExpandedEntity getEntity() {
|
|
|
1162 |
return expEntity;
|
|
|
1163 |
}
|
|
|
1164 |
|
| 198 |
naveen |
1165 |
/**
|
|
|
1166 |
* @return the current slide to edit
|
|
|
1167 |
*/
|
|
|
1168 |
public ExpandedSlideDefinition getExpandedSlideDefinition() {
|
|
|
1169 |
return expSlideDef;
|
|
|
1170 |
}
|
| 213 |
naveen |
1171 |
|
|
|
1172 |
/**
|
|
|
1173 |
*
|
|
|
1174 |
* @param slideDefID
|
|
|
1175 |
* @return
|
|
|
1176 |
*/
|
|
|
1177 |
public ExpandedSlideDefinition getExpandedSlideDefinition(long slideDefID) {
|
|
|
1178 |
try {
|
|
|
1179 |
return defs.getExpandedSlideDefinition(slideDefID);
|
|
|
1180 |
} catch (Exception e) {
|
|
|
1181 |
return null;
|
|
|
1182 |
}
|
|
|
1183 |
}
|
| 162 |
naveen |
1184 |
|
|
|
1185 |
/**
|
|
|
1186 |
*
|
|
|
1187 |
* @param id
|
|
|
1188 |
*/
|
|
|
1189 |
public void setId(String id) {
|
|
|
1190 |
this.id = id;
|
|
|
1191 |
}
|
|
|
1192 |
|
|
|
1193 |
/**
|
|
|
1194 |
*
|
|
|
1195 |
*/
|
|
|
1196 |
public String getId() {
|
|
|
1197 |
return this.id;
|
|
|
1198 |
}
|
|
|
1199 |
|
| 198 |
naveen |
1200 |
/**
|
|
|
1201 |
* @return the firstSlideID
|
|
|
1202 |
*/
|
| 213 |
naveen |
1203 |
public long getFirstSlideDefID() {
|
|
|
1204 |
return firstSlideDefID;
|
| 198 |
naveen |
1205 |
}
|
|
|
1206 |
|
| 448 |
rajveer |
1207 |
public String getCategoriesTree() throws Exception {
|
|
|
1208 |
Map<String, String> cats = new HashMap<String, String>();
|
|
|
1209 |
|
| 1051 |
rajveer |
1210 |
List<Category> children = defs.getChildrenCategories(Catalog.getInstance().getRootCategory().getID());
|
| 448 |
rajveer |
1211 |
for(Category child : children) {
|
|
|
1212 |
cats.put(new Long(child.getID()).toString(), child.getLabel());
|
|
|
1213 |
}
|
|
|
1214 |
return "";
|
|
|
1215 |
}
|
|
|
1216 |
|
| 198 |
naveen |
1217 |
public Map<String, String> getCategories() throws Exception {
|
|
|
1218 |
Map<String, String> cats = new HashMap<String, String>();
|
|
|
1219 |
|
| 1051 |
rajveer |
1220 |
List<Category> children = defs.getChildrenCategories(Catalog.getInstance().getRootCategory().getID());
|
| 198 |
naveen |
1221 |
for(Category child : children) {
|
|
|
1222 |
cats.put(new Long(child.getID()).toString(), child.getLabel());
|
|
|
1223 |
}
|
|
|
1224 |
|
|
|
1225 |
return cats;
|
|
|
1226 |
}
|
| 448 |
rajveer |
1227 |
|
| 2424 |
rajveer |
1228 |
|
|
|
1229 |
public Map<String, String> getLeafcategories() throws Exception {
|
|
|
1230 |
Map<String, String> cats = new HashMap<String, String>();
|
|
|
1231 |
List<Category> children = defs.getChildrenCategories(Catalog.getInstance().getRootCategory().getID());
|
|
|
1232 |
for(Category child : children) {
|
|
|
1233 |
if(child.getChildrenCategory() == null){
|
|
|
1234 |
cats.put(new Long(child.getID()).toString(), child.getLabel());
|
|
|
1235 |
}else{
|
|
|
1236 |
List<Category> grandChildren = defs.getChildrenCategories(child.getID());
|
|
|
1237 |
for(Category grandChild: grandChildren){
|
|
|
1238 |
if(grandChild.getChildrenCategory() == null){
|
|
|
1239 |
cats.put(new Long(grandChild.getID()).toString(), grandChild.getLabel());
|
|
|
1240 |
}
|
|
|
1241 |
}
|
|
|
1242 |
}
|
|
|
1243 |
|
|
|
1244 |
}
|
|
|
1245 |
|
|
|
1246 |
return cats;
|
|
|
1247 |
}
|
|
|
1248 |
|
| 448 |
rajveer |
1249 |
public Map<String, String> getSubcategories() throws Exception {
|
|
|
1250 |
Map<String, String> cats = new HashMap<String, String>();
|
|
|
1251 |
|
| 1051 |
rajveer |
1252 |
List<Category> children = defs.getChildrenCategories(Catalog.getInstance().getRootCategory().getID());
|
| 448 |
rajveer |
1253 |
for(Category child : children) {
|
|
|
1254 |
List<Category> grandChildren = defs.getChildrenCategories(child.getID());
|
|
|
1255 |
for(Category grandchild : grandChildren) {
|
|
|
1256 |
cats.put(new Long(grandchild.getID()).toString(), grandchild.getLabel());
|
|
|
1257 |
}
|
|
|
1258 |
}
|
|
|
1259 |
|
|
|
1260 |
return cats;
|
|
|
1261 |
}
|
|
|
1262 |
public String getCategoriesString() throws Exception {
|
|
|
1263 |
StringBuilder categoryString = new StringBuilder();
|
|
|
1264 |
|
|
|
1265 |
categoryString.append("<label for=\"basecategory\">Category: </label>");
|
|
|
1266 |
categoryString.append("\n");
|
|
|
1267 |
categoryString.append("<select id=\"basecategory\" name=\"basecategory\" >");
|
|
|
1268 |
categoryString.append("\n");
|
| 1051 |
rajveer |
1269 |
List<Category> children = defs.getChildrenCategories(Catalog.getInstance().getRootCategory().getID());
|
| 448 |
rajveer |
1270 |
for(Category child : children) {
|
|
|
1271 |
categoryString.append("<option value=\"" + new Long(child.getID()).toString() + "\">" + child.getLabel() + "</option>");
|
|
|
1272 |
categoryString.append("\n");
|
|
|
1273 |
}
|
|
|
1274 |
categoryString.append("</select>");
|
|
|
1275 |
categoryString.append("\n");
|
|
|
1276 |
categoryString.append("<br/>");
|
|
|
1277 |
categoryString.append("\n");
|
|
|
1278 |
|
|
|
1279 |
categoryString.append("<label for=\"category\">Sub Category: </label>");
|
|
|
1280 |
categoryString.append("\n");
|
|
|
1281 |
categoryString.append("<select id=\"category\" name=\"category\" >");
|
|
|
1282 |
categoryString.append("\n");
|
|
|
1283 |
for(Category child : children) {
|
|
|
1284 |
List<Category> grandChildren = defs.getChildrenCategories(child.getID());
|
|
|
1285 |
for(Category grandchild : grandChildren) {
|
|
|
1286 |
categoryString.append("<option value=\"" + new Long(grandchild.getID()).toString() + "\" selected=\"$selected\" class = \""+ child.getID() + "\">" + grandchild.getLabel() + "</option>");
|
|
|
1287 |
categoryString.append("\n");
|
|
|
1288 |
}
|
|
|
1289 |
}
|
|
|
1290 |
categoryString.append("</select>");
|
|
|
1291 |
categoryString.append("\n");
|
|
|
1292 |
categoryString.append("<br/>");
|
|
|
1293 |
|
|
|
1294 |
return categoryString.toString();
|
|
|
1295 |
|
|
|
1296 |
}
|
|
|
1297 |
|
|
|
1298 |
|
| 250 |
naveen |
1299 |
/**
|
|
|
1300 |
*
|
|
|
1301 |
* @return
|
|
|
1302 |
* @throws Exception
|
|
|
1303 |
*/
|
| 198 |
naveen |
1304 |
public String getBrandString() throws Exception {
|
|
|
1305 |
List<String> brands = this.getBrands();
|
|
|
1306 |
return "\"" + StringUtils.join(brands, "\", \"") + "\"";
|
|
|
1307 |
}
|
|
|
1308 |
|
| 250 |
naveen |
1309 |
/**
|
|
|
1310 |
*
|
|
|
1311 |
* @return
|
|
|
1312 |
* @throws Exception
|
|
|
1313 |
*/
|
| 198 |
naveen |
1314 |
public List<String> getBrands() throws Exception {
|
| 1051 |
rajveer |
1315 |
|
| 198 |
naveen |
1316 |
List<String> brands = new ArrayList<String>();
|
|
|
1317 |
|
|
|
1318 |
List<ExpandedBullet> expBullets;
|
|
|
1319 |
|
| 1051 |
rajveer |
1320 |
expBullets = CreationUtils.getLearnedBullets(Utils.BRAND_FEATURE_DEFINITION_ID);
|
|
|
1321 |
if(expBullets!=null){
|
|
|
1322 |
for(ExpandedBullet expBullet : expBullets) {
|
|
|
1323 |
brands.add(expBullet.getValue());
|
|
|
1324 |
}
|
| 198 |
naveen |
1325 |
}
|
|
|
1326 |
return brands;
|
|
|
1327 |
}
|
|
|
1328 |
|
|
|
1329 |
|
| 245 |
naveen |
1330 |
/**
|
| 198 |
naveen |
1331 |
* @param exception the exception to set
|
|
|
1332 |
*/
|
|
|
1333 |
public void setException(Exception exception) {
|
|
|
1334 |
this.exception = exception;
|
|
|
1335 |
}
|
|
|
1336 |
|
|
|
1337 |
/**
|
|
|
1338 |
* @return the exception
|
|
|
1339 |
*/
|
|
|
1340 |
public Exception getException() {
|
|
|
1341 |
return exception;
|
|
|
1342 |
}
|
|
|
1343 |
|
|
|
1344 |
/**
|
|
|
1345 |
* @param errorString the exceptionString to set
|
|
|
1346 |
*/
|
|
|
1347 |
public void setErrorString(String errorString) {
|
|
|
1348 |
this.errorString = errorString;
|
|
|
1349 |
}
|
|
|
1350 |
|
|
|
1351 |
/**
|
|
|
1352 |
* @return the exceptionString
|
|
|
1353 |
*/
|
|
|
1354 |
public String getErrorString() {
|
|
|
1355 |
return errorString;
|
|
|
1356 |
}
|
|
|
1357 |
|
|
|
1358 |
/**
|
|
|
1359 |
* @param newCurrentSlideID the newCurrentSlideID to set
|
|
|
1360 |
*/
|
|
|
1361 |
public void setNewCurrentSlideDefinitionID(
|
|
|
1362 |
long newCurrentSlideDefinitionID) {
|
|
|
1363 |
this.newCurrentSlideDefinitionID = newCurrentSlideDefinitionID;
|
|
|
1364 |
}
|
|
|
1365 |
|
|
|
1366 |
/**
|
|
|
1367 |
* @return the newCurrentSlideID
|
|
|
1368 |
*/
|
|
|
1369 |
public long getNewCurrentSlideDefinitionID() {
|
|
|
1370 |
return newCurrentSlideDefinitionID;
|
|
|
1371 |
}
|
|
|
1372 |
|
| 1051 |
rajveer |
1373 |
|
| 198 |
naveen |
1374 |
/**
|
|
|
1375 |
* @param newNextSlideID the newNextSlideID to set
|
|
|
1376 |
*/
|
|
|
1377 |
public void setNewNextSlideDefinitionID(long newNextSlideDefinitionID) {
|
|
|
1378 |
this.newNextSlideDefinitionID = newNextSlideDefinitionID;
|
|
|
1379 |
}
|
|
|
1380 |
|
|
|
1381 |
/**
|
|
|
1382 |
* @return the newNextSlideID
|
|
|
1383 |
*/
|
|
|
1384 |
public long getNewNextSlideDefinitionID() {
|
|
|
1385 |
return newNextSlideDefinitionID;
|
|
|
1386 |
}
|
|
|
1387 |
|
|
|
1388 |
/**
|
|
|
1389 |
* @param expSlide the expSlide to set
|
|
|
1390 |
*/
|
|
|
1391 |
public void setExpandedSlide(ExpandedSlide expSlide) {
|
|
|
1392 |
this.expSlide = expSlide;
|
|
|
1393 |
}
|
|
|
1394 |
|
|
|
1395 |
/**
|
|
|
1396 |
* @return the expSlide
|
|
|
1397 |
*/
|
|
|
1398 |
public ExpandedSlide getExpandedSlide() {
|
|
|
1399 |
return expSlide;
|
|
|
1400 |
}
|
|
|
1401 |
|
|
|
1402 |
/**
|
|
|
1403 |
* @param newPrevSlideDefinitionID the newPrevSlideDefinitionID to set
|
|
|
1404 |
*/
|
|
|
1405 |
public void setNewPrevSlideDefinitionID(long newPrevSlideDefinitionID) {
|
|
|
1406 |
this.newPrevSlideDefinitionID = newPrevSlideDefinitionID;
|
|
|
1407 |
}
|
|
|
1408 |
|
|
|
1409 |
/**
|
|
|
1410 |
* @return the newPrevSlideDefinitionID
|
|
|
1411 |
*/
|
|
|
1412 |
public long getNewPrevSlideDefinitionID() {
|
|
|
1413 |
return newPrevSlideDefinitionID;
|
|
|
1414 |
}
|
|
|
1415 |
|
|
|
1416 |
/**
|
| 162 |
naveen |
1417 |
*
|
| 200 |
naveen |
1418 |
* @param featureDefinitionID
|
|
|
1419 |
* @return
|
|
|
1420 |
* @throws Exception
|
|
|
1421 |
*/
|
|
|
1422 |
public String getLearnedValuesString(long featureDefinitionID)
|
|
|
1423 |
throws Exception {
|
| 206 |
naveen |
1424 |
List<String> learnedValues = this.getLearnedValues(featureDefinitionID);
|
| 6012 |
amit.gupta |
1425 |
List<String> escapedLearnedValues = new ArrayList<String>();
|
| 206 |
naveen |
1426 |
if(learnedValues == null) {
|
|
|
1427 |
return "";
|
|
|
1428 |
}
|
| 6012 |
amit.gupta |
1429 |
for(String learnedVal : learnedValues){
|
|
|
1430 |
escapedLearnedValues.add(StringEscapeUtils.escapeJavaScript(learnedVal));
|
|
|
1431 |
}
|
| 206 |
naveen |
1432 |
|
| 6012 |
amit.gupta |
1433 |
return "\"" + StringUtils.join(escapedLearnedValues, "\", \"") + "\"";
|
| 206 |
naveen |
1434 |
}
|
|
|
1435 |
|
|
|
1436 |
/**
|
|
|
1437 |
*
|
|
|
1438 |
* @param featureDefinitionID
|
|
|
1439 |
* @return
|
|
|
1440 |
* @throws Exception
|
|
|
1441 |
*/
|
|
|
1442 |
public List<String> getLearnedValues(long featureDefinitionID)
|
|
|
1443 |
throws Exception {
|
| 1051 |
rajveer |
1444 |
List<ExpandedBullet> learnedBullets = CreationUtils.getLearnedBullets(featureDefinitionID);
|
| 200 |
naveen |
1445 |
|
| 201 |
naveen |
1446 |
if(learnedBullets == null) {
|
| 206 |
naveen |
1447 |
return null;
|
| 201 |
naveen |
1448 |
}
|
|
|
1449 |
|
| 200 |
naveen |
1450 |
List<String> learnedValues = new ArrayList<String>();
|
|
|
1451 |
for(ExpandedBullet expBullet : learnedBullets) {
|
|
|
1452 |
learnedValues.add(expBullet.getValue());
|
|
|
1453 |
}
|
|
|
1454 |
|
| 206 |
naveen |
1455 |
return learnedValues;
|
| 200 |
naveen |
1456 |
}
|
|
|
1457 |
|
|
|
1458 |
/**
|
|
|
1459 |
*
|
| 201 |
naveen |
1460 |
* @param featureDefinitionID
|
|
|
1461 |
* @return
|
|
|
1462 |
* @throws Exception
|
|
|
1463 |
*/
|
|
|
1464 |
public ExpandedFeature getFeature(long featureDefinitionID)
|
|
|
1465 |
throws Exception {
|
| 215 |
naveen |
1466 |
if(this.expSlide != null) {
|
| 1152 |
rajveer |
1467 |
Feature feature = CreationUtils.getFeature(this.expSlide, featureDefinitionID);
|
| 215 |
naveen |
1468 |
|
|
|
1469 |
if(feature == null) {
|
|
|
1470 |
return null;
|
|
|
1471 |
}
|
|
|
1472 |
return new ExpandedFeature(feature);
|
| 201 |
naveen |
1473 |
}
|
|
|
1474 |
|
| 215 |
naveen |
1475 |
return null;
|
| 201 |
naveen |
1476 |
}
|
|
|
1477 |
|
|
|
1478 |
/**
|
|
|
1479 |
*
|
| 162 |
naveen |
1480 |
* @return
|
|
|
1481 |
*/
|
| 208 |
naveen |
1482 |
public String getEditorialImportance() {
|
| 242 |
naveen |
1483 |
// Now that slides are selected upfront
|
|
|
1484 |
return "Mandatory";
|
|
|
1485 |
|
|
|
1486 |
/*
|
| 208 |
naveen |
1487 |
long catID = this.expEntity.getCategoryID();
|
|
|
1488 |
long slideDefID = this.getNewCurrentSlideDefinitionID();
|
|
|
1489 |
|
|
|
1490 |
try {
|
|
|
1491 |
List<CategorySlideDefinition> catSlideDefs =
|
|
|
1492 |
defs.getCategorySlideDefinitions(catID);
|
|
|
1493 |
for(CategorySlideDefinition catSlideDef : catSlideDefs) {
|
|
|
1494 |
if(catSlideDef.getSlideDefintionID() == slideDefID) {
|
|
|
1495 |
return catSlideDef.getEditorialImportance().toString();
|
|
|
1496 |
}
|
|
|
1497 |
}
|
|
|
1498 |
} catch (Exception e) {
|
|
|
1499 |
log.error(CreationUtils.getStackTrace(e));
|
|
|
1500 |
}
|
|
|
1501 |
|
|
|
1502 |
return "";
|
| 242 |
naveen |
1503 |
*/
|
| 162 |
naveen |
1504 |
}
|
| 210 |
naveen |
1505 |
|
| 242 |
naveen |
1506 |
|
| 1051 |
rajveer |
1507 |
|
| 242 |
naveen |
1508 |
/**
|
|
|
1509 |
*
|
|
|
1510 |
* @return
|
|
|
1511 |
*/
|
|
|
1512 |
public String getCategoryName(long categoryID) {
|
| 739 |
chandransh |
1513 |
if(categoryID==-1)
|
|
|
1514 |
return "Yet to be Asssigned";
|
| 242 |
naveen |
1515 |
try {
|
| 1051 |
rajveer |
1516 |
return this.defs.getCategory(categoryID).getLabel();
|
|
|
1517 |
|
| 242 |
naveen |
1518 |
} catch (Exception e) {
|
|
|
1519 |
return null;
|
|
|
1520 |
}
|
|
|
1521 |
}
|
| 250 |
naveen |
1522 |
|
|
|
1523 |
/**
|
|
|
1524 |
*
|
|
|
1525 |
* @return
|
|
|
1526 |
*/
|
|
|
1527 |
public List<String[]> getSlides() {
|
|
|
1528 |
try {
|
|
|
1529 |
long entityID = Long.parseLong(this.getId());
|
| 1051 |
rajveer |
1530 |
List<Long> slideDefIDs = CreationUtils.getEntity(entityID).getSlideSequence();
|
| 250 |
naveen |
1531 |
|
|
|
1532 |
List<String[]> slideData = new ArrayList<String[]>();
|
| 1051 |
rajveer |
1533 |
|
| 250 |
naveen |
1534 |
for(Long slideDefID : slideDefIDs) {
|
|
|
1535 |
SlideDefinition slideDef = defs.getSlideDefinition(slideDefID);
|
|
|
1536 |
String label = slideDef.getLabel();
|
|
|
1537 |
|
|
|
1538 |
slideData.add(new String[] {slideDefID.toString(), label});
|
|
|
1539 |
}
|
|
|
1540 |
|
|
|
1541 |
return slideData;
|
|
|
1542 |
} catch (Exception e) {
|
|
|
1543 |
log.error(CreationUtils.getStackTrace(e));
|
|
|
1544 |
|
|
|
1545 |
return null;
|
|
|
1546 |
}
|
|
|
1547 |
}
|
| 4129 |
mandeep.dh |
1548 |
|
|
|
1549 |
public String getCatalogDetails() {
|
|
|
1550 |
try {
|
|
|
1551 |
CatalogClient catalogServiceClient = new CatalogClient();
|
|
|
1552 |
items = catalogServiceClient.getClient().getItemsByCatalogId(entityId);
|
| 5945 |
mandeep.dh |
1553 |
} catch (CatalogServiceException e) {
|
| 4129 |
mandeep.dh |
1554 |
log.error("Could not fetch item for entity id: " + entityId, e);
|
|
|
1555 |
} catch (TException e) {
|
|
|
1556 |
log.error("Could not fetch item for enitty id: " + entityId, e);
|
|
|
1557 |
}
|
|
|
1558 |
|
|
|
1559 |
return "catalog-details";
|
|
|
1560 |
}
|
|
|
1561 |
|
|
|
1562 |
public String convertDate(long date) {
|
|
|
1563 |
SimpleDateFormat sdf = new SimpleDateFormat("dd MMM, yyyy hh:mm a");
|
|
|
1564 |
return sdf.format(new Date(date));
|
|
|
1565 |
}
|
|
|
1566 |
|
| 250 |
naveen |
1567 |
/**
|
|
|
1568 |
*
|
|
|
1569 |
* @param entityID
|
|
|
1570 |
* @return
|
|
|
1571 |
* @throws Exception
|
|
|
1572 |
*/
|
|
|
1573 |
private ExpandedEntity getExpandedEntity(long entityID) throws Exception {
|
|
|
1574 |
if(this.expEntity == null) {
|
|
|
1575 |
if(this.entity == null) {
|
| 1051 |
rajveer |
1576 |
this.entity = CreationUtils.getEntity(entityID);
|
| 250 |
naveen |
1577 |
}
|
| 1051 |
rajveer |
1578 |
this.expEntity = new ExpandedEntity(entity);
|
| 250 |
naveen |
1579 |
}
|
|
|
1580 |
|
|
|
1581 |
return this.expEntity;
|
|
|
1582 |
}
|
|
|
1583 |
|
| 1051 |
rajveer |
1584 |
public Map<Long, EntityState> getEntitiesState(){
|
|
|
1585 |
return this.entitiesState;
|
|
|
1586 |
}
|
|
|
1587 |
|
|
|
1588 |
public Set<String> getAllUserNames(){
|
|
|
1589 |
return UserManager.getUserManager().getAllUserNames();
|
|
|
1590 |
}
|
|
|
1591 |
|
|
|
1592 |
public Collection<User> getAllUsers(){
|
|
|
1593 |
return UserManager.getUserManager().getAllUsers();
|
|
|
1594 |
}
|
|
|
1595 |
|
| 2095 |
rajveer |
1596 |
public List<Long> getInconsistentEntities(){
|
|
|
1597 |
return this.inconsistentEntities;
|
|
|
1598 |
}
|
| 4129 |
mandeep.dh |
1599 |
|
|
|
1600 |
/**
|
|
|
1601 |
* @return the entityId
|
|
|
1602 |
*/
|
|
|
1603 |
public long getEntityId() {
|
|
|
1604 |
return entityId;
|
|
|
1605 |
}
|
|
|
1606 |
|
|
|
1607 |
/**
|
|
|
1608 |
* @param entityId the entityId to set
|
|
|
1609 |
*/
|
|
|
1610 |
public void setEntityId(long entityId) {
|
|
|
1611 |
this.entityId = entityId;
|
|
|
1612 |
}
|
|
|
1613 |
|
|
|
1614 |
/**
|
|
|
1615 |
* @return the items
|
|
|
1616 |
*/
|
|
|
1617 |
public List<Item> getItems() {
|
|
|
1618 |
return items;
|
|
|
1619 |
}
|
|
|
1620 |
|
|
|
1621 |
/**
|
|
|
1622 |
* @param items the items to set
|
|
|
1623 |
*/
|
|
|
1624 |
public void setItems(List<Item> items) {
|
|
|
1625 |
this.items = items;
|
|
|
1626 |
}
|
| 5180 |
amit.gupta |
1627 |
|
|
|
1628 |
public String getJavascriptSafe(String string){
|
|
|
1629 |
return StringEscapeUtils.escapeJavaScript(string);
|
|
|
1630 |
}
|
| 6877 |
amit.gupta |
1631 |
|
|
|
1632 |
public String getFormattedDate(Date date){
|
|
|
1633 |
return sdf.format(date);
|
|
|
1634 |
}
|
| 7958 |
amit.gupta |
1635 |
|
| 8025 |
amit.gupta |
1636 |
public Map<Object, Double> getScores() throws Exception{
|
| 7971 |
amit.gupta |
1637 |
Long entityId = Long.parseLong(this.id);
|
| 8025 |
amit.gupta |
1638 |
Map<Object,Double> finalScores = new HashMap<Object, Double>();
|
| 7965 |
amit.gupta |
1639 |
EntityState es = CreationUtils.getEntityState(entityId);
|
| 7966 |
amit.gupta |
1640 |
if (es!=null && es.getCategoryID() > 0) {
|
| 7973 |
amit.gupta |
1641 |
if((es.getCategoryID() == 10002l || es.getCategoryID() == 10003l || es.getCategoryID() == 10004l || es.getCategoryID() == 10005l) && !es.getStatus().equals(EntityStatus.UNASSIGNED)){
|
| 7966 |
amit.gupta |
1642 |
NewCMP cmp = new NewCMP(Arrays.asList(this.entity));
|
|
|
1643 |
try {
|
| 8024 |
amit.gupta |
1644 |
//get Scores on the basis of evaluation
|
| 7975 |
amit.gupta |
1645 |
Map<Long, Map<Long, Double>> scoreMap = cmp.getSlideScores(0);
|
| 8025 |
amit.gupta |
1646 |
finalScores = new HashMap<Object, Double>(scoreMap.get(entityId));
|
|
|
1647 |
finalScores.put(130054L, cmp.getFinalScores(scoreMap).get(entityId)/10);
|
| 8024 |
amit.gupta |
1648 |
finalScores.put("actual", cmp.getFinalScores(scoreMap).get(entityId)/10);
|
| 7966 |
amit.gupta |
1649 |
|
| 8024 |
amit.gupta |
1650 |
Map<Long, Double> customScores = CreationUtils.getCustomSlideComparisonScores(entityId);
|
|
|
1651 |
if(customScores != null){
|
|
|
1652 |
//now update scoreMap if any of the slide score has been customised
|
|
|
1653 |
for (Map.Entry<Long, Double> entry : scoreMap.get(entityId).entrySet()){
|
|
|
1654 |
if(customScores.containsKey(entry.getKey())){
|
|
|
1655 |
entry.setValue(customScores.get(entry.getKey()));
|
|
|
1656 |
}
|
|
|
1657 |
}
|
|
|
1658 |
finalScores.put("custom", cmp.getFinalScores(scoreMap).get(entityId)/10);
|
|
|
1659 |
}
|
|
|
1660 |
|
| 7966 |
amit.gupta |
1661 |
} catch (Exception e) {
|
|
|
1662 |
System.out.println("Some error occurred");
|
|
|
1663 |
e.printStackTrace();
|
|
|
1664 |
}
|
|
|
1665 |
DecimalFormat oneDForm = new DecimalFormat("#.#");
|
| 8025 |
amit.gupta |
1666 |
for(Map.Entry<Object, Double> scoreEntry : finalScores.entrySet()){
|
| 7966 |
amit.gupta |
1667 |
scoreEntry.setValue(Double.valueOf(oneDForm.format(scoreEntry.getValue())));
|
|
|
1668 |
}
|
| 8024 |
amit.gupta |
1669 |
return finalScores;
|
| 7966 |
amit.gupta |
1670 |
} else {
|
| 8025 |
amit.gupta |
1671 |
return new HashMap<Object, Double>();
|
| 7966 |
amit.gupta |
1672 |
}
|
| 7963 |
amit.gupta |
1673 |
} else {
|
| 8025 |
amit.gupta |
1674 |
return new HashMap<Object, Double>();
|
| 7963 |
amit.gupta |
1675 |
}
|
| 7958 |
amit.gupta |
1676 |
}
|
|
|
1677 |
|
| 1051 |
rajveer |
1678 |
|
|
|
1679 |
}
|
| 448 |
rajveer |
1680 |
|