Subversion Repositories SmartDukaan

Rev

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

Rev 516 Rev 739
Line 27... Line 27...
27
import in.shop2020.metamodel.util.ExpandedFeature;
27
import in.shop2020.metamodel.util.ExpandedFeature;
28
import in.shop2020.metamodel.util.ExpandedFeatureDefinition;
28
import in.shop2020.metamodel.util.ExpandedFeatureDefinition;
29
import in.shop2020.metamodel.util.ExpandedSlide;
29
import in.shop2020.metamodel.util.ExpandedSlide;
30
import in.shop2020.metamodel.util.ExpandedSlideDefinition;
30
import in.shop2020.metamodel.util.ExpandedSlideDefinition;
31
import in.shop2020.metamodel.util.SequenceGenerator;
31
import in.shop2020.metamodel.util.SequenceGenerator;
-
 
32
import in.shop2020.model.v1.catalog.Item;
-
 
33
import in.shop2020.model.v1.catalog.status;
-
 
34
import in.shop2020.thrift.clients.CatalogServiceClient;
32
import in.shop2020.util.Utils;
35
import in.shop2020.util.Utils;
33
 
36
 
34
import java.util.ArrayList;
37
import java.util.ArrayList;
35
import java.util.Arrays;
38
import java.util.Arrays;
36
import java.util.Collection;
39
import java.util.Collection;
Line 129... Line 132...
129
    // GET /entity
132
    // GET /entity
130
    public HttpHeaders index() {
133
    public HttpHeaders index() {
131
    	log.info("EntityController.index");
134
    	log.info("EntityController.index");
132
    	
135
    	
133
    	EntityContainer ents = new EntityContainer();
136
    	EntityContainer ents = new EntityContainer();
134
    	
137
    	createEntitiesForItemsInProcess();
135
    	try {
138
    	try {
136
			this.entities = ents.getEntities().values();
139
			this.entities = ents.getEntities().values();
137
			this.catEntities = ents.getEntitiesbyCategory();
140
			this.catEntities = ents.getEntitiesbyCategory();
138
		} catch (Exception e) {
141
		} catch (Exception e) {
139
			log.error(CreationUtils.getStackTrace(e));
142
			log.error(CreationUtils.getStackTrace(e));
Line 1061... Line 1064...
1061
			log.error(CreationUtils.getStackTrace(e));
1064
			log.error(CreationUtils.getStackTrace(e));
1062
			this.setErrorString(CreationUtils.getStackTrace(e));
1065
			this.setErrorString(CreationUtils.getStackTrace(e));
1063
			return null;
1066
			return null;
1064
		}
1067
		}
1065
	}
1068
	}
-
 
1069
 
-
 
1070
	/**
-
 
1071
	 * Inquires about items in the IN_PROCESS state with the Catalog service and
-
 
1072
	 * creates those entities which do not exist in the CMS already.
-
 
1073
	 * 
-
 
1074
	 * @return A List of entities fetched from the catalog.
-
 
1075
	 */
-
 
1076
	private void createEntitiesForItemsInProcess(){
-
 
1077
		try {
-
 
1078
			CatalogServiceClient csc = new CatalogServiceClient();
-
 
1079
			in.shop2020.model.v1.catalog.InventoryService.Client iclient = csc.getClient();
-
 
1080
			List<Item> items = iclient.getAllItemsByStatus(status.IN_PROCESS);
-
 
1081
			for(Item item: items){
-
 
1082
				long entityID = item.getCatalogItemId();
-
 
1083
				if(CreationUtils.getEntity(entityID) == null){
-
 
1084
					log.info("#### Going to add the entity with id: ####" + entityID);
-
 
1085
					Entity entity = new Entity(entityID, -1);
-
 
1086
					entity.setBrand(item.getManufacturerName());
-
 
1087
					entity.setModelNumber(item.getModelNumber());
-
 
1088
					entity.setModelName((item.getModelName()==null) ? "" : item.getModelName());
-
 
1089
					addEntity(entity);
-
 
1090
				}else
-
 
1091
					log.info("###Everything went all right and we got an entity");
-
 
1092
			}
-
 
1093
		} catch (Exception e) {
-
 
1094
			e.printStackTrace();
-
 
1095
		}
-
 
1096
	}
1066
	
1097
	
1067
    /**
1098
    /**
1068
	 * @return the entities
1099
	 * @return the entities
1069
	 */
1100
	 */
1070
	public ExpandedEntity getEntity() {
1101
	public ExpandedEntity getEntity() {
Line 1530... Line 1561...
1530
	/**
1561
	/**
1531
	 * 
1562
	 * 
1532
	 * @return
1563
	 * @return
1533
	 */
1564
	 */
1534
	public String getCategoryName(long categoryID) {
1565
	public String getCategoryName(long categoryID) {
-
 
1566
		if(categoryID==-1)
-
 
1567
			return "Yet to be Asssigned";
1535
		try {
1568
		try {
1536
			return this.getDefinitionsContainer().getCategory(categoryID).
1569
			return this.getDefinitionsContainer().getCategory(categoryID).
1537
				getLabel();
1570
				getLabel();
1538
		} catch (Exception e) {
1571
		} catch (Exception e) {
1539
			return null;
1572
			return null;
Line 1591... Line 1624...
1591
     * @param entityID
1624
     * @param entityID
1592
     * @return
1625
     * @return
1593
     * @throws Exception 
1626
     * @throws Exception 
1594
     */
1627
     */
1595
    private Entity getEntity(long entityID) throws Exception {
1628
    private Entity getEntity(long entityID) throws Exception {
1596
    	log.info("#### EntityController.getEntity ####");
1629
    	log.info("Getting entity with id : " + entityID);
1597
		if(this.entity == null) {
1630
		if(this.entity == null) {
1598
			this.entity = CreationUtils.getEntity(entityID);
1631
			this.entity = CreationUtils.getEntity(entityID);
1599
		}
1632
		}
1600
		
1633
		
1601
		return this.entity;
1634
		return this.entity;