public List<Event> getEvents() { return Arrays.<Event>asList(new EntityUpdatedEvent(), new EntityCreatedEvent()); } }
public void addEntityToList(EntityList list, UUID entity) throws EntityDoesNotExistException { EntityList originalList; originalList = getStoredEntityList(list); if (originalList == null) { this.dao.commit(); throw new EntityDoesNotExistException(); } getObservationManager().notify(new EntityUpdatingEvent(), originalList); this.dao.addEntityToList(list.getId(), entity); getObservationManager().notify(new EntityUpdatedEvent(), originalList); }
public HomePage getOrCreate(HomePage homePage) throws InvalidEntityException { HomePage original; this.dao.begin(); original = this.find(); if (original != null) { this.dao.commit(); return original; } getObservationManager().notify(new EntityCreatingEvent(), homePage); UUID entityId = UUID.randomUUID(); homePage.setId(entityId); this.dao.createEntityIfItDoesNotExist(homePage, HOME_PAGE_TYPE, getTenant()); this.dao.commit(); getObservationManager().notify(new EntityCreatedEvent(), homePage); return this.find(); }
public void update(Collection collection) throws EntityDoesNotExistException, InvalidEntityException { this.dao.begin(); Collection originalCollection = this.dao.findBySlug(collection.getSlug(), getTenant()); if (originalCollection == null) { this.dao.commit(); throw new EntityDoesNotExistException(); } collection.setId(originalCollection.getId()); Integer updatedRows = this.dao.update(collection); this.dao.createOrUpdateAddons(collection); if (collection.getLocalizedVersions() != null && !collection.getLocalizedVersions().isEmpty()) { Map<Locale, Map<String, Object>> localizedVersions = collection.getLocalizedVersions(); for (Locale locale : localizedVersions.keySet()) { this.dao.createOrUpdateTranslation(collection.getId(), locale, localizedVersions.get(locale)); } } this.dao.commit(); if (updatedRows <= 0) { throw new StoreException("No rows was updated when updating collection"); } getObservationManager().notify(new EntityUpdatedEvent(), collection); }
@Override public Customer create(@Valid Customer customer) throws EntityAlreadyExistsException, InvalidEntityException { if (this.exists(customer.getSlug())) { throw new EntityAlreadyExistsException(); } getObservationManager().notify(new EntityCreatingEvent(), customer); this.dao.begin(); UUID entityId = UUID.randomUUID(); customer.setId(entityId); if (getTenant() == null) { this.dao.createEntity(customer, CUSTOMER_TABLE_NAME); } else { this.dao.createEntity(customer, CUSTOMER_TABLE_NAME, getTenant()); } this.dao.create(customer); this.dao.commit(); getObservationManager().notify(new EntityCreatedEvent(), customer); return customer; }
public void removeEntityFromList(EntityList list, UUID entity) throws EntityDoesNotExistException { EntityList originalList; originalList = getStoredEntityList(list); if (originalList == null) { this.dao.commit(); throw new EntityDoesNotExistException(); } getObservationManager().notify(new EntityUpdatingEvent(), originalList); this.dao.removeEntityFromList(list.getId(), entity); getObservationManager().notify(new EntityUpdatedEvent(), originalList); }
public void updateStock(UUID productId, Integer stockOffset) throws EntityDoesNotExistException { this.dao.begin(); Product product = this.findById(productId); if (product == null) { this.dao.commit(); throw new EntityDoesNotExistException(); } product.setStock((product.getStock() == null ? 0 : product.getStock()) + stockOffset); Integer updatedRows = this.dao.updateProduct(product); this.dao.commit(); if (updatedRows <= 0) { throw new StoreException("No rows was updated when updating product"); } getObservationManager().notify(new EntityUpdatedEvent(), product); }
public EntityList create(@Valid EntityList list) throws EntityAlreadyExistsException, InvalidEntityException { EntityList originalList; this.dao.begin(); originalList = getStoredEntityList(list); if (originalList != null) { this.dao.commit(); throw new EntityAlreadyExistsException(); } getObservationManager().notify(new EntityCreatingEvent(), list); UUID entityId = UUID.randomUUID(); list.setId(entityId); if (list.getParentId() != null) { this.dao.createChildEntity(list, ENTITY_LIST_TABLE_NAME, getTenant()); } else { this.dao.createEntity(list, ENTITY_LIST_TABLE_NAME, getTenant()); } this.dao.createEntityList(list); this.dao.commit(); getObservationManager().notify(new EntityCreatedEvent(), list); return list; }
public void update(@Valid HomePage entity) throws EntityDoesNotExistException, InvalidEntityException { this.dao.begin(); HomePage homePage = find(); if (homePage == null) { this.dao.commit(); throw new EntityDoesNotExistException(); } getObservationManager().notify(new EntityUpdatingEvent(), entity); entity.setId(homePage.getId()); this.dao.createOrUpdateAddons(entity); this.dao.commit(); getObservationManager().notify(new EntityUpdatedEvent(), entity); }
public EntityList getOrCreate(EntityList list) throws InvalidEntityException { EntityList originalList; this.dao.begin(); originalList = getStoredEntityList(list); if (originalList != null) { this.dao.commit(); return originalList; } getObservationManager().notify(new EntityCreatingEvent(), list); UUID entityId = UUID.randomUUID(); list.setId(entityId); Integer created; if (list.getParentId() != null) { created = this.dao.createChildEntityIfItDoesNotExist(list, ENTITY_LIST_TABLE_NAME, getTenant()); } else { created = this.dao.createEntityIfItDoesNotExist(list, ENTITY_LIST_TABLE_NAME, getTenant()); } if (created > 0) { this.dao.createEntityList(list); } this.dao.commit(); getObservationManager().notify(new EntityCreatedEvent(), list); return getStoredEntityList(list); }
public void update(@Valid EntityList list) throws EntityDoesNotExistException, InvalidEntityException { EntityList originalList; this.dao.begin(); originalList = getStoredEntityList(list); if (originalList == null) { this.dao.commit(); throw new EntityDoesNotExistException(); } getObservationManager().notify(new EntityUpdatingEvent(), list); list.setId(originalList.getId()); Integer updatedRows = this.dao.updateEntityList(list); this.dao.commit(); if (updatedRows <= 0) { throw new StoreException("No rows was updated when updating list"); } getObservationManager().notify(new EntityUpdatedEvent(), list); }
public Collection create(Collection collection) throws EntityAlreadyExistsException, InvalidEntityException { if (this.dao.findBySlug(collection.getSlug(), getTenant(), collection.getParentId()) != null) { throw new EntityAlreadyExistsException(); } getObservationManager().notify(new EntityCreatingEvent(), collection); this.dao.begin(); UUID entityId = UUID.randomUUID(); collection.setId(entityId); this.dao.createEntity(collection, COLLECTION_TABLE_NAME, getTenant()); Integer lastIndex = this.dao.lastPosition(getTenant()); this.dao.create(lastIndex == null ? 0 : ++lastIndex, collection); // this.dao.insertTranslations(entityId, collection.getTranslations()); this.dao.createOrUpdateAddons(collection); this.dao.commit(); getObservationManager().notify(new EntityCreatedEvent(), collection); return collection; }
public void update(Product product) throws EntityDoesNotExistException, InvalidEntityException { this.dao.begin(); Product originalProduct = this.findBySlug(product.getSlug(), product.getParentId()); if (originalProduct == null) { this.dao.commit(); throw new EntityDoesNotExistException(); } if (!product.getAddons().isLoaded()) { product.setAddons(originalProduct.getAddons().get()); } getObservationManager().notify(new EntityUpdatingEvent(), product); product.setId(originalProduct.getId()); Integer updatedRows = this.dao.updateProduct(product); this.dao.createOrUpdateAddons(product); if (product.getLocalizedVersions() != null && !product.getLocalizedVersions().isEmpty()) { Map<Locale, Map<String, Object>> localizedVersions = product.getLocalizedVersions(); for (Locale locale : localizedVersions.keySet()) { this.dao.createOrUpdateTranslation(product.getId(), locale, localizedVersions.get(locale)); } } this.dao.commit(); if (updatedRows <= 0) { throw new StoreException("No rows was updated when updating product"); } getObservationManager().notify(new EntityUpdatedEvent(), product); }
public Feature createFeature(final Feature feature) throws InvalidEntityException, EntityAlreadyExistsException { if (feature.getParentId() == null) { throw new InvalidEntityException("Cannot create a feature without a parent product specified"); } Product product = this.findById(feature.getParentId()); if (product == null) { throw new InvalidEntityException("Specified parent product does not exist"); } boolean exists = findFeature(product, feature.getFeature(), feature.getFeatureSlug()) != null; if (exists) { throw new EntityAlreadyExistsException(); } if (!feature.getAddons().isLoaded()) { feature.setAddons(new HashMap<String, AddonGroup>()); } getObservationManager().notify(new EntityCreatingEvent(), feature); this.featureDao.begin(); UUID entityId = UUID.randomUUID(); feature.setId(entityId); this.featureDao.createChildEntity(feature, FEATURE_TABLE_NAME, getTenant()); this.featureDao.createFeature(feature); this.featureDao.createOrUpdateAddons(feature); this.featureDao.commit(); getObservationManager().notify(new EntityCreatedEvent(), feature); return feature; }
getObservationManager().notify(new EntityCreatingEvent(), product); getObservationManager().notify(new EntityCreatedEvent(), product);