public URI getRegisteredURI(MCRBase obj) throws URISyntaxException { return new URI(this.registerURL + registerURLContext.replaceAll("\\$[iI][dD]", obj.getId().toString())); }
public List<MCRPIRegistrationInfo> getRegistered(MCRBase object) { EntityManager em = MCREntityManagerProvider.getCurrentEntityManager(); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<MCRPIRegistrationInfo> getQuery = cb.createQuery(MCRPIRegistrationInfo.class); Root<MCRPI> pi = getQuery.from(MCRPI.class); return em.createQuery( getQuery .select(pi) .where( cb.equal(pi.get(MCRPI_.mycoreID), object.getId().toString()))) .getResultList(); }
protected void validatePermission(MCRBase obj) throws MCRAccessException { String missingPermission; if (!MCRAccessManager.checkPermission(obj.getId(), missingPermission = PERMISSION_WRITE) || !MCRAccessManager .checkPermission(obj.getId(), missingPermission = "register-" + getServiceID())) { throw MCRAccessException .missingPermission("Register a " + type + " & Update object.", obj.getId().toString(), missingPermission); } }
private void startRegisterJob(MCRBase obj, MCRDigitalObjectIdentifier newDOI) { HashMap<String, String> contextParameters = new HashMap<>(); contextParameters.put(CONTEXT_DOI, newDOI.asString()); contextParameters.put(CONTEXT_OBJ, obj.getId().toString()); this.addRegisterJob(contextParameters); }
protected String buildTargetURL(MCRBase obj) { String baseURL = getProperties().get(PURL_BASE_URL); return baseURL + getProperties().getOrDefault(PURL_CONTEXT_CONFIG, DEFAULT_CONTEXT_PATH) .replaceAll("\\$[iI][dD]", obj.getId().toString()); }
private void startUpdateJob(MCRBase obj, MCRPURL purl) { HashMap<String, String> contextParameters = new HashMap<>(); contextParameters.put(CONTEXT_PURL, purl.asString()); contextParameters.put(CONTEXT_OBJECT, obj.getId().toString()); this.addUpdateJob(contextParameters); }
@Override protected void update(MCRPURL purl, MCRBase obj, String additional) throws MCRPersistentIdentifierException { if (!hasRegistrationStarted(obj.getId(), additional)) { Predicate<MCRBase> registrationCondition = getRegistrationCondition(obj.getId().getTypeId()); if (registrationCondition.test(obj)) { this.updateStartRegistrationDate(obj.getId(), "", new Date()); startRegisterJob(obj, purl); } } else { if (isRegistered(obj.getId(), "")) { startUpdateJob(obj, purl); } } }
private void startRegisterJob(MCRBase obj, MCRPURL purl) { HashMap<String, String> contextParameters = new HashMap<>(); contextParameters.put(CONTEXT_PURL, purl.asString()); contextParameters.put(CONTEXT_OBJECT, obj.getId().toString()); this.addRegisterJob(contextParameters); }
@Override public void update(MCRDigitalObjectIdentifier doi, MCRBase obj, String additional) throws MCRPersistentIdentifierException { if (isRegistered(obj.getId(), additional)) { HashMap<String, String> contextParameters = new HashMap<>(); contextParameters.put(CONTEXT_DOI, doi.asString()); contextParameters.put(CONTEXT_OBJ, obj.getId().toString()); this.addUpdateJob(contextParameters); } else if (!hasRegistrationStarted(obj.getId(), additional)) { Predicate<MCRBase> registrationCondition = getRegistrationCondition(obj.getId().getTypeId()); if (registrationCondition.test(obj)) { this.updateStartRegistrationDate(obj.getId(), "", new Date()); startRegisterJob(obj, doi); } } }
/** * Validates if an object can get an Identifier assigned from this service! <b>Better call super when overwrite!</b> * * @param obj * @throws MCRPersistentIdentifierException see {@link org.mycore.pi.exceptions} * @throws MCRAccessException if the user does not have the rights to assign a pi to the specific object */ public void validateRegistration(MCRBase obj, String additional) throws MCRPersistentIdentifierException, MCRAccessException { validateAlreadyCreated(obj.getId(), additional); validatePermission(obj); }
@Override public MCRDigitalObjectIdentifier generate(MCRBase mcrObject, String additional) throws MCRPersistentIdentifierException { final MCRObjectID objectId = mcrObject.getId(); return Optional.ofNullable(getProperties().get("Prefix." + objectId.getBase())) .map(prefix -> { final int objectIdNumberAsInteger = objectId.getNumberAsInteger(); return prefix.contains("/") ? prefix + objectIdNumberAsInteger : prefix + '/' + objectIdNumberAsInteger; }) .flatMap(mcrdoiParser::parse).map(MCRDigitalObjectIdentifier.class::cast) .orElseThrow(() -> new MCRPersistentIdentifierException("Prefix." + objectId.getBase() + " is not defined in " + generatorID + ".")); }
@Override public MCRDNBURN generate(MCRBase mcrObj, String additional) throws MCRPersistentIdentifierException { return generate(getNamespace(), mcrObj.getId(), additional); }
@Override public MCRDNBURN register(MCRBase obj, String filePath, boolean updateObject) throws MCRAccessException, MCRActiveLinkException, MCRPersistentIdentifierException { this.validateRegistration(obj, filePath); if (obj instanceof MCRDerivate) { MCRDerivate derivate = (MCRDerivate) obj; return registerURN(derivate, filePath); } else { throw new MCRPersistentIdentifierException("Object " + obj.getId() + " is not a MCRDerivate!"); } }
@Override public MCRPI insertIdentifierToDatabase(MCRBase obj, String additional, MCRDigitalObjectIdentifier identifier) { Date registrationStarted = null; if (getRegistrationCondition(obj.getId().getTypeId()).test(obj)) { registrationStarted = new Date(); startRegisterJob(obj, identifier); } MCRPI databaseEntry = new MCRPI(identifier.asString(), getType(), obj.getId().toString(), additional, this.getServiceID(), provideRegisterDate(obj, additional), registrationStarted); MCRHIBConnection.instance().getSession().save(databaseEntry); return databaseEntry; }
@Override public MCRPI insertIdentifierToDatabase(MCRBase obj, String additional, MCRPURL identifier) { Date registrationStarted = null; if (getRegistrationCondition(obj.getId().getTypeId()).test(obj)) { registrationStarted = new Date(); startRegisterJob(obj, identifier); } MCRPI databaseEntry = new MCRPI(identifier.asString(), getType(), obj.getId().toString(), additional, this.getServiceID(), provideRegisterDate(obj, additional), registrationStarted); MCRHIBConnection.instance().getSession().save(databaseEntry); return databaseEntry; }
private void handleBaseUpdated(final MCRBase obj) { final MIRAccessKeyPair accKP = MIRAccessKeyPairTransformer.buildAccessKeyPair(obj.createXML().getRootElement()); if (accKP != null) { LOGGER.debug("Update access keys for " + obj.getId().toString()); MIRAccessKeyManager.updateKeyPair(accKP); removeAccessKeys(obj); } }
private void handleBaseCreated(final MCRBase obj) { final MIRAccessKeyPair accKP = MIRAccessKeyPairTransformer.buildAccessKeyPair(obj.createXML().getRootElement()); if (accKP != null) { LOGGER.debug("Create access keys for " + obj.getId().toString()); MIRAccessKeyManager.createKeyPair(accKP); removeAccessKeys(obj); } }
private void handleBaseDeleted(final MCRBase obj) { final MIRAccessKeyPair accKP = MIRAccessKeyPairTransformer.buildAccessKeyPair(obj.createXML().getRootElement()); if (accKP != null) { LOGGER.debug("Delete access keys for " + obj.getId().toString()); MIRAccessKeyManager.deleteKeyPair(accKP.getMCRObjectId()); removeAccessKeys(obj); } }
public MCRPI insertIdentifierToDatabase(MCRBase obj, String additional, T identifier) { MCRPI databaseEntry = new MCRPI(identifier.asString(), getType(), obj.getId().toString(), additional, this.getServiceID(), provideRegisterDate(obj, additional), null); MCRHIBConnection.instance().getSession().save(databaseEntry); return databaseEntry; }
protected final void onDelete(T identifier, MCRBase obj, String additional) throws MCRPersistentIdentifierException { delete(identifier, obj, additional); MCRPIManager.getInstance().delete(obj.getId().toString(), additional, getType(), this.getServiceID()); }