Subversion Repositories SmartDukaan

Rev

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

Rev 37652 Rev 37822
Line 86... Line 86...
86
	 * fault and must surface here, rather than leave an internal store quietly billing to a stale
86
	 * fault and must surface here, rather than leave an internal store quietly billing to a stale
87
	 * address, which is the failure this sync exists to end.
87
	 * address, which is the failure this sync exists to end.
88
	 */
88
	 */
89
	@Override
89
	@Override
90
	public int syncInternalStoreAddresses(int warehouseId) throws ProfitMandiBusinessException {
90
	public int syncInternalStoreAddresses(int warehouseId) throws ProfitMandiBusinessException {
-
 
91
		WarehouseAddressMaster master = this.mappedAddress(warehouseId);
-
 
92
		String stateName = this.stateName(master);
-
 
93
 
-
 
94
		int synced = 0;
-
 
95
		for (FofoStore store : fofoStoreRepository.selectActivePartnerByWarehouse(warehouseId)) {
-
 
96
			if (!FofoType.INTERNAL.equals(store.getFofoType())) {
-
 
97
				continue;
-
 
98
			}
-
 
99
			this.applyAddress(store, master, stateName);
-
 
100
			synced++;
-
 
101
		}
-
 
102
		return synced;
-
 
103
	}
-
 
104
 
-
 
105
	@Override
-
 
106
	public void syncInternalStoreAddress(FofoStore store) throws ProfitMandiBusinessException {
-
 
107
		if (!FofoType.INTERNAL.equals(store.getFofoType())) {
-
 
108
			return;
-
 
109
		}
-
 
110
		WarehouseAddressMaster master = this.mappedAddress(store.getWarehouseId());
-
 
111
		this.applyAddress(store, master, this.stateName(master));
-
 
112
	}
-
 
113
 
-
 
114
	private WarehouseAddressMaster mappedAddress(int warehouseId) throws ProfitMandiBusinessException {
91
		WarehouseAddressMapping mapping = warehouseAddressMappingRepository.selectByWarehouseId(warehouseId);
115
		WarehouseAddressMapping mapping = warehouseAddressMappingRepository.selectByWarehouseId(warehouseId);
92
		if (mapping == null) {
116
		if (mapping == null) {
93
			throw new ProfitMandiBusinessException("Warehouse Address Mapping", warehouseId,
117
			throw new ProfitMandiBusinessException("Warehouse Address Mapping", warehouseId,
94
					"No address is mapped to this warehouse");
118
					"No address is mapped to this warehouse");
95
		}
119
		}
96
		WarehouseAddressMaster master = warehouseAddressMasterRepository.selectById(mapping.getAddressId());
120
		return warehouseAddressMasterRepository.selectById(mapping.getAddressId());
-
 
121
	}
-
 
122
 
97
		CustomAddress warehouseAddress = master.getCustomAddress();
123
	private String stateName(WarehouseAddressMaster master) throws ProfitMandiBusinessException {
98
		String stateName;
-
 
99
		try {
124
		try {
100
			stateName = stateRepository.selectById(master.getStateId()).getName();
125
			return stateRepository.selectById(master.getStateId()).getName();
101
		} catch (Exception e) {
126
		} catch (Exception e) {
102
			throw new ProfitMandiBusinessException("Warehouse Address State", master.getStateId(),
127
			throw new ProfitMandiBusinessException("Warehouse Address State", master.getStateId(),
103
					"Problem while fetching state");
128
					"Problem while fetching state");
104
		}
129
		}
-
 
130
	}
105
 
131
 
106
		int synced = 0;
-
 
107
		for (FofoStore store : fofoStoreRepository.selectActivePartnerByWarehouse(warehouseId)) {
132
	private void applyAddress(FofoStore store, WarehouseAddressMaster master, String stateName)
108
			if (!FofoType.INTERNAL.equals(store.getFofoType())) {
133
			throws ProfitMandiBusinessException {
109
				continue;
134
		CustomAddress warehouseAddress = master.getCustomAddress();
110
			}
-
 
111
			User user = userUserRepository.selectById(store.getId());
135
		User user = userUserRepository.selectById(store.getId());
112
			Address address = addressRepository.selectById(user.getAddressId());
136
		Address address = addressRepository.selectById(user.getAddressId());
113
			address.setLine1(warehouseAddress.getLine1());
137
		address.setLine1(warehouseAddress.getLine1());
114
			address.setLine2(warehouseAddress.getLine2());
138
		address.setLine2(warehouseAddress.getLine2());
115
			address.setCity(warehouseAddress.getCity());
139
		address.setCity(warehouseAddress.getCity());
116
			address.setState(stateName);
140
		address.setState(stateName);
117
			address.setPinCode(warehouseAddress.getPinCode());
141
		address.setPinCode(warehouseAddress.getPinCode());
118
			address.setUpdateTimestamp(LocalDateTime.now());
142
		address.setUpdateTimestamp(LocalDateTime.now());
119
			addressRepository.persist(address);
143
		addressRepository.persist(address);
120
			synced++;
-
 
121
		}
-
 
122
		return synced;
-
 
123
	}
144
	}
124
}
145
}