use of org.mycore.pi.backend.MCRPI in project mycore by MyCoRe-Org.
the class MCRPIRegistrationService method insertIdentifierToDatabase.
public MCRPI insertIdentifierToDatabase(MCRBase obj, String additional, T identifier) {
MCRPI databaseEntry = new MCRPI(identifier.asString(), getType(), obj.getId().toString(), additional, this.getRegistrationServiceID(), provideRegisterDate(obj, additional), null);
MCRHIBConnection.instance().getSession().save(databaseEntry);
return databaseEntry;
}
use of org.mycore.pi.backend.MCRPI in project mycore by MyCoRe-Org.
the class MCRPersistentIdentifierManager method delete.
public void delete(String objectID, String additional, String type, String service) {
Objects.requireNonNull(objectID, "objectId may not be null");
Objects.requireNonNull(type, "type may not be null");
Objects.requireNonNull(additional, "additional may not be null");
Objects.requireNonNull(service, "service may not be null");
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<MCRPI> getQuery = cb.createQuery(MCRPI.class);
Root<MCRPI> pi = getQuery.from(MCRPI.class);
em.remove(em.createQuery(getQuery.where(cb.equal(pi.get(MCRPI_.mycoreID), objectID), cb.equal(pi.get(MCRPI_.type), type), cb.equal(pi.get(MCRPI_.additional), additional), cb.equal(pi.get(MCRPI_.service), service))).getSingleResult());
}
use of org.mycore.pi.backend.MCRPI in project mycore by MyCoRe-Org.
the class MCRPICommands method removeControlFromObject.
@MCRCommand(syntax = "remove control {0} with service {1} with additional {2}", help = "This commands removes the " + "pi control from the object {0}(object id) with the serivce {1}(service id) and the additional {2}")
public static void removeControlFromObject(String objectIDString, String serviceID, String additional) throws MCRAccessException, MCRActiveLinkException, MCRPersistentIdentifierException {
MCRObjectID objectID = MCRObjectID.getInstance(objectIDString);
MCRPI mcrpi = MCRPersistentIdentifierManager.getInstance().get(serviceID, objectIDString, additional != null ? additional.trim() : null);
MCRPersistentIdentifierManager.getInstance().delete(mcrpi.getMycoreID(), mcrpi.getAdditional(), mcrpi.getType(), mcrpi.getService());
MCRBase base = MCRMetadataManager.retrieve(objectID);
if (MCRPIRegistrationService.removeFlagFromObject(base, mcrpi) == null) {
throw new MCRPersistentIdentifierException("Could not delete Flag of object (flag not found)!");
}
MCRMetadataManager.update(base);
}
use of org.mycore.pi.backend.MCRPI in project mycore by MyCoRe-Org.
the class MCRPICommands method controlObjectWithServiceAndAdditional.
@MCRCommand(syntax = "try to control {0} with service {1} with additional {2}", help = "This command tries to" + " read a pi from the object {0} with the MetadataManager from the specified service {1}." + " If the service configuration is right then the pi is under control of MyCoRe.")
public static void controlObjectWithServiceAndAdditional(String objectIDString, String serviceID, final String additional) throws MCRAccessException, MCRActiveLinkException, IOException {
String trimAdditional = additional.trim();
MCRPIRegistrationService<MCRPersistentIdentifier> service = MCRPIRegistrationServiceManager.getInstance().getRegistrationService(serviceID);
MCRPersistentIdentifierMetadataManager<MCRPersistentIdentifier> metadataManager = service.getMetadataManager();
MCRObjectID objectID = MCRObjectID.getInstance(objectIDString);
MCRBase mcrBase = MCRMetadataManager.retrieve(objectID);
Optional<MCRPersistentIdentifier> identifier;
try {
identifier = metadataManager.getIdentifier(mcrBase, trimAdditional);
} catch (MCRPersistentIdentifierException e) {
LOGGER.info("Could not detect any identifier with service {}", serviceID, e);
return;
}
if (!identifier.isPresent()) {
LOGGER.info("Could not detect any identifier with service {}", serviceID);
return;
}
MCRPersistentIdentifier persistentIdentifier = identifier.get();
if (service.isRegistered(objectID, trimAdditional)) {
LOGGER.info("Already present in Database: {}", serviceID);
return;
}
MCRPI mcrpi = service.insertIdentifierToDatabase(mcrBase, trimAdditional, persistentIdentifier);
MCRPIRegistrationService.addFlagToObject(mcrBase, mcrpi);
MCRMetadataManager.update(mcrBase);
LOGGER.info("{}:{} is now under control of {}", objectID, trimAdditional, serviceID);
}
use of org.mycore.pi.backend.MCRPI in project mycore by MyCoRe-Org.
the class MCRPIJobRegistrationService method updateRegistrationDate.
/**
* Can be used to update the registration date in the database. The most {@link MCRPIJobRegistrationService}
* only add the pi to the object and then to the database, with registration date of null. Later the job will
* register the pi and then change the registration date to the right value.
* <b>If you use this methods from a job you should have called {@link #validateJobUserRights} before!</b>
* @param mycoreID the id of the {@link org.mycore.datamodel.metadata.MCRBase} which has the pi assigned
* @param additional information like path to a file
* @param date the new registration date
*/
protected void updateRegistrationDate(MCRObjectID mycoreID, String additional, Date date) {
MCRPI pi = MCRPersistentIdentifierManager.getInstance().get(this.getRegistrationServiceID(), mycoreID.toString(), additional);
pi.setRegistered(date);
updateFlag(mycoreID, additional, pi);
}
Aggregations