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