private static void copyFlagToProperty(MCRBase obj, JsonObject json, String flagName, String propertyName) { obj.getService() .getFlags(flagName) .stream() .findFirst() .ifPresent(c -> { json.addProperty(propertyName, c); }); }
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); } }
public URI getRegisteredURI(MCRBase obj) throws URISyntaxException { return new URI(this.registerURL + registerURLContext.replaceAll("\\$[iI][dD]", obj.getId().toString())); }
final Date objectCreateDate = mcrBase.getService().getDate(MCRObjectService.DATE_TYPE_CREATEDATE); resultingPI = resultingPI.replace(PLACE_HOLDER_OBJECT_DATE, getDateFormat().format(objectCreateDate)); final String mappedObjectType = getMappedType(mcrBase.getId()); resultingPI = resultingPI.replace(PLACE_HOLDER_OBJECT_TYPE, mappedObjectType); final String mappedObjectProject = getMappedProject(mcrBase.getId()); resultingPI = resultingPI.replace(PLACE_HOLDER_OBJECT_PROJECT, mappedObjectProject); resultingPI = resultingPI.replace(PLACE_HOLDER_OBJECT_NUMBER, mcrBase.getId().getNumberAsString());
@Override public void removeIdentifier(MCRPersistentIdentifier identifier, MCRBase obj, String additional) { String xpath = getProperties().get("Xpath"); Document xml = obj.createXML(); XPathFactory xPathFactory = XPathFactory.instance(); XPathExpression<Element> xp = xPathFactory.compile(xpath, Filters.element()); List<Element> elements = xp.evaluate(xml); elements.stream() .filter(element -> element.getTextTrim().equals(identifier.asString())) .forEach(Element::detach); }
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(); }
@Override public MCRDigitalObjectIdentifier generate(MCRBase mcrObj, String additional) throws MCRPersistentIdentifierException { Date createdate = mcrObj.getService().getDate("createdate"); if (createdate != null) { MCRISO8601Date mcrdate = new MCRISO8601Date(); mcrdate.setDate(createdate); String createDate = mcrdate.format(DATE_PATTERN, Locale.ENGLISH); final int count = getCountForCreateDate(createDate); Optional<MCRDigitalObjectIdentifier> parse = mcrdoiParser.parse(prefix + "/" + createDate + "-" + count); MCRPersistentIdentifier doi = parse.orElseThrow(() -> new MCRException("Error while parsing default doi!")); return (MCRDigitalObjectIdentifier) doi; } else { throw new MCRPersistenceException("The object " + mcrObj.getId() + " doesn't have a createdate!"); } }
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 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 static void copyServiceDateToProperty(MCRBase obj, JsonObject jsonObj, String dateType, String propertyName) { Optional.ofNullable(obj.getService().getDate(dateType)) .map(Date::toInstant) .map(Instant::toString) .ifPresent(d -> jsonObj.addProperty(propertyName, d)); }
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); }
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); } }
@Override public Predicate<MCRBase> provideRegistrationCondition(String type) { return (MCRBase base) -> { return Optional.ofNullable(base.getService().getState()) .map(state -> state.getID().equals("published")) .orElse(false); }; } }
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()); }
@Override public Optional<MCRPersistentIdentifier> getIdentifier(MCRBase obj, String additional) throws MCRPersistentIdentifierException { String xpath = getProperties().get("Xpath"); Document xml = obj.createXML(); XPathFactory xpfac = XPathFactory.instance(); XPathExpression<Element> xp = xpfac .compile(xpath, Filters.element(), null, MCRConstants.getStandardNamespaces()); List<Element> evaluate = xp.evaluate(xml); if (evaluate.size() > 1) { throw new MCRPersistentIdentifierException( "Got " + evaluate.size() + " matches for " + obj.getId() + " with xpath " + xpath + ""); } if (evaluate.size() == 0) { return Optional.empty(); } Element identifierElement = evaluate.listIterator().next(); String identifierString = identifierElement.getTextNormalize(); Optional<MCRPersistentIdentifier> parsedIdentifierOptional = MCRPIManager.getInstance() .getParserForType(getProperties().get("Type")).parse(identifierString); return parsedIdentifierOptional.map(MCRPersistentIdentifier.class::cast); }
public static void addFlagToObject(MCRBase obj, MCRPI databaseEntry) { String json = getGson().toJson(databaseEntry); obj.getService().addFlag(PI_FLAG, json); }
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 public void insertIdentifier(MCRPersistentIdentifier identifier, MCRBase obj, String additional) throws MCRPersistentIdentifierException { String xpath = getProperties().get("Xpath"); Document xml = obj.createXML(); MCRNodeBuilder nb = new MCRNodeBuilder(); try { nb.buildElement(xpath, identifier.asString(), xml); if (obj instanceof MCRObject) { final Element metadata = xml.getRootElement().getChild("metadata"); ((MCRObject) obj).getMetadata().setFromDOM(metadata); } else { throw new MCRPersistentIdentifierException(obj.getId() + " is no MCRObject!", new OperationNotSupportedException(getClass().getName() + " only supports " + MCRObject.class.getName() + "!")); } } catch (Exception e) { throw new MCRException("Error while inscribing PI to " + obj.getId(), e); } }
public static boolean hasFlag(MCRBase obj, String additional, MCRPIRegistrationInfo mcrpi) { MCRObjectService service = obj.getService(); ArrayList<String> flags = service.getFlags(MCRPIService.PI_FLAG); Gson gson = getGson(); return flags.stream().anyMatch(_stringFlag -> { MCRPI flag = gson.fromJson(_stringFlag, MCRPI.class); return flag.getAdditional().equals(additional) && flag.getIdentifier().equals(mcrpi.getIdentifier()); }); }
@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); } } }