Subversion Repositories SmartDukaan

Rev

Rev 1739 | Rev 2292 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1739 Rev 2287
Line 40... Line 40...
40
import in.shop2020.metamodel.util.CreationUtils;
40
import in.shop2020.metamodel.util.CreationUtils;
41
import in.shop2020.metamodel.util.ExpandedEntity;
41
import in.shop2020.metamodel.util.ExpandedEntity;
42
//import in.shop2020.metamodel.util.OldCreationUtils;
42
//import in.shop2020.metamodel.util.OldCreationUtils;
43
//import in.shop2020.metamodel.util.OldCreationUtils;
43
//import in.shop2020.metamodel.util.OldCreationUtils;
44
import in.shop2020.metamodel.util.ExpandedBullet;
44
import in.shop2020.metamodel.util.ExpandedBullet;
-
 
45
import in.shop2020.model.v1.catalog.InventoryService.Client;
-
 
46
import in.shop2020.model.v1.catalog.Item;
-
 
47
import in.shop2020.model.v1.catalog.status;
-
 
48
import in.shop2020.thrift.clients.CatalogServiceClient;
45
 
49
 
46
 
50
 
47
/*
51
/*
48
 * @author rajveer 
52
 * @author rajveer 
49
 * 
53
 * 
Line 51... Line 55...
51
 */
55
 */
52
 
56
 
53
public class ContentMigrator {
57
public class ContentMigrator {
54
	private String sourceDbPath;
58
	private String sourceDbPath;
55
	private String destinationDbPath;
59
	private String destinationDbPath;
56
	
-
 
57
	public static void main(String[] args) throws Exception {
60
	public static void main(String[] args) throws Exception {
58
		String usage = "Usage: ContentMigrator {source db path}{destination db path}";
61
		String usage = "Usage: ContentMigrator {source db path}{destination db path}";
59
		
62
		
60
		String sourceDbPath = null, destinationDbPath = null;
63
		String sourceDbPath = null, destinationDbPath = null; String dryRun = null;
61
		if(args.length < 2) {
64
		if(args.length < 2) {
62
			System.out.println(usage);
65
			System.out.println(usage);
63
			System.exit(-1);
66
			System.exit(-1);
64
		}else{
67
		}else{
65
			sourceDbPath = args[0];
68
			sourceDbPath = args[0];
66
			destinationDbPath = args[1];
69
			destinationDbPath = args[1];
-
 
70
			dryRun = args[2];
67
		}
71
		}
68
		
72
		
69
		ContentMigrator contentmigrator = new ContentMigrator(sourceDbPath, destinationDbPath);
73
		ContentMigrator contentmigrator = new ContentMigrator(sourceDbPath, destinationDbPath);
-
 
74
		contentmigrator.migrateBrandModel(dryRun);
70
		contentmigrator.migrateData();
75
		//contentmigrator.migrateData();
71
		//contentmigrator.migrateRemoveBorrowedCategoryIdFromSlide();
76
		//contentmigrator.migrateRemoveBorrowedCategoryIdFromSlide();
72
		//contentmigrator.migrateModel1();
77
		//contentmigrator.migrateModel1();
73
		//contentmigrator.changeEntityState();
78
		//contentmigrator.changeEntityState();
74
		//contentmigrator.removeBrowserBullets();
79
		//contentmigrator.removeBrowserBullets();
75
		//contentmigrator.migrateModel2();
80
		//contentmigrator.migrateModel2();
Line 112... Line 117...
112
 
117
 
113
	public ContentMigrator(String sourceDbPath, String destinationDbPath) {
118
	public ContentMigrator(String sourceDbPath, String destinationDbPath) {
114
		this.sourceDbPath = sourceDbPath;
119
		this.sourceDbPath = sourceDbPath;
115
		this.destinationDbPath = destinationDbPath;
120
		this.destinationDbPath = destinationDbPath;
116
	}
121
	}
-
 
122
	
-
 
123
	
-
 
124
	public boolean migrateBrandModel(String dryRun) throws Exception{
-
 
125
		CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
-
 
126
		Client client = catalogServiceClient.getClient();
-
 
127
		List<Item> items = client.getAllItemsByStatus(status.ACTIVE);
-
 
128
		items.addAll(client.getAllItemsByStatus(status.PAUSED));
-
 
129
		items.addAll(client.getAllItemsByStatus(status.CONTENT_COMPLETE));
-
 
130
		Map<Long, Entity> entities = CreationUtils.getEntities();
-
 
131
		long count = 0;
-
 
132
		StringBuffer sb = new StringBuffer();
-
 
133
		for(Item item:items){
-
 
134
			long entityId = item.getCatalogItemId();
-
 
135
			Entity entity = entities.get(entityId);
-
 
136
			String itemBrand = item.getBrand();
-
 
137
			String itemModelName = item.getModelName();
-
 
138
			String itemModelNumber = item.getModelNumber();
-
 
139
			String entityBrand = entity.getBrand();
-
 
140
			String entityModelName = entity.getModelName();
-
 
141
			String entityModelNumber = entity.getModelNumber();
-
 
142
			
-
 
143
			if(itemBrand.equals(entityBrand) && itemModelName.equals(entityModelName) && itemModelNumber.equals(entityModelNumber)){
-
 
144
				continue;
-
 
145
			}
-
 
146
			count++;
-
 
147
			sb.append(count + ") Item:   " + itemBrand + " " + itemModelName + " " + itemModelNumber);
-
 
148
			sb.append(count + ") Entity: " + entityBrand + " " + entityModelName + " " + entityModelNumber);
-
 
149
			if(dryRun.equals("false")){
-
 
150
				item.setBrand(entity.getBrand());
-
 
151
				item.setModelName(entity.getModelName());
-
 
152
				item.setModelNumber(entity.getModelNumber());
-
 
153
				client.updateItem(item);				
-
 
154
			}
-
 
155
		}
-
 
156
		System.out.println(sb.toString());
-
 
157
		return true;
-
 
158
	}
-
 
159
	
117
	/**
160
	/**
118
	 * this function will read source definition and source entities, and will convert
161
	 * this function will read source definition and source entities, and will convert
119
	 * source entities to destination entities according to destination definitions.  
162
	 * source entities to destination entities according to destination definitions.  
120
	 * 
163
	 * 
121
	 * @return boolean
164
	 * @return boolean