@Override public void deleteCollection(String collectionSlug) throws EntityDoesNotExistException { Collection collection = this.findCollectionBySlug(collectionSlug); if (collection == null) { throw new EntityDoesNotExistException(); } this.collectionStore.get().delete(collection); }
@Override public void removeProductFromCollection(String collection, String product) throws InvalidOperation { Collection c = this.findCollectionBySlug(collection); Product p = this.findProductBySlug(product); if (p == null || c == null) { throw new InvalidOperation("Product or collection does not exist"); } List<Collection> collections = this.collectionStore.get().findAllForProduct(p); if (!collections.contains(c)) { // It does not contain it : nothing to do return; } this.collectionStore.get().removeProduct(c, p); }
@Override public void addProductToCollection(String collection, String product) throws InvalidOperation { Collection c = this.findCollectionBySlug(collection); Product p = this.findProductBySlug(product); if (p == null || c == null) { throw new InvalidOperation("Product or collection does not exist"); } List<Collection> collections = this.collectionStore.get().findAllForProduct(p); if (collections.contains(c)) { // Already has it : nothing to do return; } this.collectionStore.get().addProduct(c, p); }
@Override public Collection createCollection(Collection entity) throws InvalidEntityException, EntityAlreadyExistsException { if (Strings.isNullOrEmpty(entity.getSlug())) { entity.setSlug(this.slugifier.slugify(entity.getTitle())); } this.collectionStore.get().create(entity); return this.findCollectionBySlug(entity.getSlug()); }