@Override public void checkSetup() throws MCRConfigurationException, MCRAccessException { Map<String, String> parameters = this.getParameters(); if (!parameters.containsKey("objectId")) { throw new MCRUsageException("No ObjectID in parameters!"); } MCRObjectID objectID = getObjectID(); MCRObject mcrObject = MCRMetadataManager.retrieveMCRObject(objectID); Optional<String> ppn = detectPPN(mcrObject, ""); if (!ppn.isPresent()) { throw new MCRUsageException("No PPN detected in object: " + objectID.toString()); } if (!parameters.containsKey("packer")) { throw new MCRException("Packer is undefined! This should be impossible!"); } String packer = parameters.get("packer"); checkACL(objectID, packer); }
/** * Add the access key to the given {@link MCRUser} for {@link MCRObjectID}. * * @param user the {@link MCRUser} * @param mcrObjectId the {@link MCRObjectID} * @param accessKey the access key * @throws MCRUsageException * if an error was occured */ public static void addAccessKey(final MCRUser user, final MCRObjectID mcrObjectId, final String accessKey) throws MCRUsageException { if (getAccessKeyType(mcrObjectId, accessKey) == null) throw new MCRUsageException("Invalid access key \"" + accessKey + "\""); user.getAttributes().put(ACCESS_KEY_PREFIX + mcrObjectId.toString(), accessKey); MCRUserManager.updateUser(user); }
private void handleModify(Map<String, Element> cache, Element element) { if ("modify".equals(element.getName())) { String refID = element.getAttributeValue(ATTR_REF); if (refID == null) { throw new MCRUsageException("<xed:modify /> must have a @ref attribute!"); } Element container = cache.get(refID); if (container == null) { LOGGER.warn("Ignoring xed:modify of " + refID + ", no component with that @id found"); return; } container = container.clone(); String newID = element.getAttributeValue(ATTR_ID); if (newID != null) { container.setAttribute(ATTR_ID, newID); // extend rather that modify LOGGER.debug("extending " + refID + " to " + newID); } else { LOGGER.debug("modifying " + refID); } for (Element command : element.getChildren()) { String commandType = command.getName(); if ("remove".equals(commandType)) { handleRemove(container, command); } else if ("include".equals(commandType)) { handleInclude(container, command); } } cacheComponent(cache, container); } }
} catch (NamingException ex) { String msg = "Exception accessing LDAP server"; throw new MCRUsageException(msg, ex); } finally { if (ctx != null) {
LOGGER.info("Command processed ({} ms)", System.currentTimeMillis() - start); } else { throw new MCRUsageException("Command not understood: " + command);