public void updateItem(Item master, SiteProfileClass siteProfileClasses[]) throws Exception {
if (siteProfileClasses == null) {
siteProfileClasses = getSiteProfileClasses();
}
CompassSession compassSession = compass.openSession();
CompassTransaction compassTransaction = compassSession.beginTransaction();
String query = "+itemId:" + master.getItemId().toString();
CompassHits hits = compassSession.find(query);
Iterator<?> iterator = hits.detach().iterator();
while (iterator.hasNext()) {
DefaultCompassHit defaultCompassHit = (DefaultCompassHit) iterator.next();
compassSession.delete(defaultCompassHit.getData());
}
if (!master.getItemTypeCd().equals(Constants.ITEM_TYPE_SKU)) {
if (isShareInventory) {
for (SiteProfileClass siteProfileClass : siteProfileClasses) {
boolean found = false;
for (ItemLanguage language : master.getItemLanguages()) {
if (language.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClass.getSiteProfileClassId())) {
found = true;
CompassItemLanguage compassItemLanguage = formatItemLanguage(master, language, -1L);
compassSession.save(compassItemLanguage);
}
}
if (!found) {
CompassItemLanguage compassItemLanguage = formatItemLanguage(master, master.getItemLanguage(), -1L);
compassItemLanguage.setSiteProfileClassId(siteProfileClass.getSiteProfileClassId());
compassSession.save(compassItemLanguage);
}
}
}
else {
for (SiteDomain siteDomain : master.getSiteDomains()) {
for (SiteProfileClass siteProfileClass : siteProfileClasses) {
boolean found = false;
for (ItemLanguage language : master.getItemLanguages()) {
if (language.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClass.getSiteProfileClassId())) {
found = true;
CompassItemLanguage compassItemLanguage = formatItemLanguage(master, language, siteDomain.getSiteDomainId());
compassSession.save(compassItemLanguage);
}
}
if (!found) {
CompassItemLanguage compassItemLanguage = formatItemLanguage(master, master.getItemLanguage(), siteDomain.getSiteDomainId());
compassItemLanguage.setSiteProfileClassId(siteProfileClass.getSiteProfileClassId());
compassSession.save(compassItemLanguage);
}
}
}
}
}
compassTransaction.commit();
compassSession.close();
}