/** * Returns true of the given {@link MCRObjectID} has a mods type. Does not look at the object. * @param id - the {@link MCRObjectID} * @return true if has a mods type */ public static boolean isSupported(MCRObjectID id) { return SUPPORTED_TYPES.contains(id.getTypeId()); }
private String getMappedType(MCRObjectID id) { String mapping = getObjectTypeMapping(); String typeID = id.getTypeId(); return Optional.ofNullable(mapping) .map(mappingStr -> mappingStr.split(",")) .map(Arrays::asList) .filter(o -> o.get(0).equals(typeID)) .map(o -> o.get(1)) .orElse(typeID); }
protected String formatURI(String uri, String id, String metadataPrefix) { MCRObjectID mcrID = MCRObjectID.isValid(id) ? MCRObjectID.getInstance(id) : null; boolean exists; String objectType; if (mcrID != null) { exists = MCRMetadataManager.exists(mcrID); objectType = mcrID.getTypeId(); } else { MCRFilesystemNode node = MCRFilesystemNode.getNode(id); exists = node != null; objectType = "data_file"; } return uri.replace("{id}", id).replace("{format}", metadataPrefix).replace("{objectType}", objectType).replace( ":{flag}", !exists ? ":deletedMcrObject" : ""); }
/** * Returns a list with identifiers of the deleted objects within the given date boundary. * If the record policy indicates that there is no support for tracking deleted an empty * list is returned. * * @param from from date * @param until to date * * @return a list with identifiers of the deleted objects */ protected List<Header> searchDeleted(Instant from, Instant until) { DeletedRecordPolicy deletedRecordPolicy = this.identify.getDeletedRecordPolicy(); if (from == null || DeletedRecordPolicy.No.equals(deletedRecordPolicy) || DeletedRecordPolicy.Transient.equals(deletedRecordPolicy)) { return new ArrayList<>(); } LOGGER.info("Getting identifiers of deleted items"); Map<MCRObjectID, Instant> deletedItems = MCRMetadataHistoryManager.getDeletedItems(from, Optional.ofNullable(until)); List<String> types = getConfig().getStrings(getConfigPrefix() + "DeletedRecordTypes", null); if (types == null || types.isEmpty()) { return deletedItems.entrySet().stream() .map(this::toHeader) .collect(Collectors.toList()); } return deletedItems.entrySet().stream() .filter(e -> types.contains(e.getKey().getTypeId())) .map(this::toHeader) .collect(Collectors.toList()); }
@GET @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON + ";charset=UTF-8" }) @MCRCacheControl(maxAge = @MCRCacheControl.Age(time = 1000, unit = TimeUnit.DAYS), sMaxAge = @MCRCacheControl.Age(time = 1000, unit = TimeUnit.DAYS)) //will never expire actually @Path("/{" + PARAM_MCRID + "}/versions/{revision}") @Operation( summary = "Returns MCRObject with the given " + PARAM_MCRID + " and revision.", tags = MCRRestUtils.TAG_MYCORE_OBJECT) public Response getObjectVersion(@Parameter(example = "mir_mods_00004711") @PathParam(PARAM_MCRID) MCRObjectID id, @PathParam("revision") long revision) throws IOException { MCRContent mcrContent = MCRXMLMetadataManager.instance().retrieveContent(id, revision); if (mcrContent == null) { throw new NotFoundException( Response.status(Response.Status.NOT_FOUND).entity("revision_not_found").build()); } long modified = mcrContent.lastModified(); Date lastModified = new Date(modified); Optional<Response> cachedResponse = MCRRestUtils.getCachedResponse(request, lastModified); if (cachedResponse.isPresent()) { return cachedResponse.get(); } LogManager.getLogger().info("OK: {}", mcrContent.getETag()); return Response.ok() .entity(mcrContent, new Annotation[] { MCRParams.Factory .get(MCRParam.Factory.get(MCRContentAbstractWriter.PARAM_OBJECTTYPE, id.getTypeId())) }) .lastModified(lastModified) .build(); }
@GET @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON + ";charset=UTF-8" }) @MCRCacheControl(maxAge = @MCRCacheControl.Age(time = 1, unit = TimeUnit.DAYS), sMaxAge = @MCRCacheControl.Age(time = 1, unit = TimeUnit.DAYS)) @Operation( summary = "Returns given derivate in the given object", tags = MCRRestUtils.TAG_MYCORE_DERIVATE) @Path("/{" + PARAM_DERID + "}") public Response getDerivate(@Parameter(example = "mir_derivate_00004711") @PathParam(PARAM_DERID) MCRObjectID derid) throws IOException { validateDerivateRelation(mcrId, derid); long modified = MCRXMLMetadataManager.instance().getLastModified(derid); Date lastModified = new Date(modified); Optional<Response> cachedResponse = MCRRestUtils.getCachedResponse(request, lastModified); if (cachedResponse.isPresent()) { return cachedResponse.get(); } MCRContent mcrContent = MCRXMLMetadataManager.instance().retrieveContent(derid); return Response.ok() .entity(mcrContent, new Annotation[] { MCRParams.Factory .get(MCRParam.Factory.get(MCRContentAbstractWriter.PARAM_OBJECTTYPE, derid.getTypeId())) }) .lastModified(lastModified) .build(); }
private boolean checkObjectPermission(MCRObjectID objectId, String permission) { LOGGER.debug("checkObjectPermission({}, {})", objectId, permission); // 1. check read or write key of current user if (KEY_STRATEGY_HELPER.checkObjectPermission(objectId, permission)) { return true; } // 2. check if access mapping for object id exists String permissionId = objectId.toString(); if (ID_STRATEGY.hasRuleMapping(permissionId, permission)) { LOGGER.debug("Found match in ID strategy for {} on {}.", permission, objectId); return ID_STRATEGY.checkPermission(permissionId, permission); } // 3. check if creator rule applies if (CREATOR_STRATEGY.isCreatorRuleAvailable(permissionId, permission)) { LOGGER.debug("Found match in CREATOR strategy for {} on {}.", permission, objectId); return CREATOR_STRATEGY.checkPermission(permissionId, permission); } return getAccessCategory(objectId, objectId.getTypeId(), permission) // 4. check if classification rule applies .map(c -> { LOGGER.debug("using access rule defined for category: " + c); return ACCESS_IMPL.checkPermission(objectId.getTypeId() + ":" + c.toString(), permission); }) //5. fallback to MCRObjectBaseStrategy .orElseGet(() -> { LOGGER.debug("Using BASE strategy as fallback for {} on {}.", permission, objectId); return OBJECT_BASE_STRATEGY.checkPermission(permissionId, permission); }); }
@GET @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON + ";charset=UTF-8" }) @MCRCacheControl(maxAge = @MCRCacheControl.Age(time = 1, unit = TimeUnit.DAYS), sMaxAge = @MCRCacheControl.Age(time = 1, unit = TimeUnit.DAYS)) @Path("/{" + PARAM_MCRID + "}") @Operation( summary = "Returns MCRObject with the given " + PARAM_MCRID + ".", tags = MCRRestUtils.TAG_MYCORE_OBJECT) public Response getObject(@Parameter(example = "mir_mods_00004711") @PathParam(PARAM_MCRID) MCRObjectID id) throws IOException { long modified = MCRXMLMetadataManager.instance().getLastModified(id); if (modified < 0) { throw new NotFoundException("MCRObject " + id + " not found"); } Date lastModified = new Date(modified); Optional<Response> cachedResponse = MCRRestUtils.getCachedResponse(request, lastModified); if (cachedResponse.isPresent()) { return cachedResponse.get(); } MCRContent mcrContent = MCRXMLMetadataManager.instance().retrieveContent(id); return Response.ok() .entity(mcrContent, new Annotation[] { MCRParams.Factory .get(MCRParam.Factory.get(MCRContentAbstractWriter.PARAM_OBJECTTYPE, id.getTypeId())) }) .lastModified(lastModified) .build(); }
@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 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); } } }
@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; }
@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); } } }
throws MCRPersistenceException, MCRActiveLinkException, MCRAccessException, IOException { MCRObjectID derivateID = MCRObjectID.getInstance(derId); if (!derivateID.getTypeId().equals("derivate")) { LOGGER.error("Command needs derivate as parameter: ", derId); return;
@Override protected void handleObjectUpdated(final MCREvent evt, final MCRObject obj) { if (!MCRMODSWrapper.isSupported(obj)) { return; } handleObjectCreated(evt, obj); //may have to reindex children, if they inherit any information for (MCRMetaLinkID childLinkID : obj.getStructure().getChildren()) { MCRObjectID childID = childLinkID.getXLinkHrefID(); if (MCRMetadataManager.exists(childID)) { MCREvent childEvent = new MCREvent(childID.getTypeId(), MCREvent.INDEX_EVENT); childEvent.put("object", MCRMetadataManager.retrieve(childID)); MCREventManager.instance().handleEvent(childEvent); } } }