@Override public Bundle create(Context context, Item item, String name) throws SQLException, AuthorizeException { if (StringUtils.isBlank(name)) { throw new SQLException("Bundle must be created with non-null name"); } authorizeService.authorizeAction(context, item, Constants.ADD); // Create a table row Bundle bundle = bundleDAO.create(context, new Bundle()); bundle.setName(context, name); itemService.addBundle(context, item, bundle); if (!bundle.getItems().contains(item)) { bundle.addItem(item); } log.info(LogManager.getHeader(context, "create_bundle", "bundle_id=" + bundle.getID())); // if we ever use the identifier service for bundles, we should // create the bundle before we create the Event and should add all // identifiers to it. context.addEvent(new Event(Event.CREATE, Constants.BUNDLE, bundle.getID(), null)); return bundle; }
@Override public void addBundle(Context context, Item item, Bundle bundle) throws SQLException, AuthorizeException { // Check authorisation authorizeService.authorizeAction(context, item, Constants.ADD); log.info(LogManager.getHeader(context, "add_bundle", "item_id=" + item.getID() + ",bundle_id=" + bundle.getID())); // Check it's not already there if (item.getBundles().contains(bundle)) { // Bundle is already there; no change return; } // now add authorization policies from owning item // hmm, not very "multiple-inclusion" friendly authorizeService.inheritPolicies(context, item, bundle); // Add the bundle to in-memory list item.addBundle(bundle); bundle.addItem(item); context.addEvent(new Event(Event.ADD, Constants.ITEM, item.getID(), Constants.BUNDLE, bundle.getID(), bundle.getName(), getIdentifiers(context, item))); }