use of org.mycore.datamodel.metadata.MCRMetaIFS in project mycore by MyCoRe-Org.
the class MCRRestAPIUploadHelper method uploadDerivate.
/**
* creates or updates a MyCoRe derivate
* @param info - the Jersey UriInfo object
* @param request - the HTTPServletRequest object
* @param mcrObjID - the MyCoRe Object ID
* @param label - the label of the new derivate
* @param overwriteOnExistingLabel, if true an existing MyCoRe derivate with the given label will be returned
* @return a Jersey Response object
* @throws MCRRestAPIException
*/
public static Response uploadDerivate(UriInfo info, HttpServletRequest request, String mcrObjID, String label, boolean overwriteOnExistingLabel) throws MCRRestAPIException {
Response response = Response.status(Status.INTERNAL_SERVER_ERROR).build();
SignedJWT signedJWT = MCRJSONWebTokenUtil.retrieveAuthenticationToken(request);
// File fXML = null;
MCRObjectID mcrObjIDObj = MCRObjectID.getInstance(mcrObjID);
try (MCRJPATransactionWrapper mtw = new MCRJPATransactionWrapper()) {
MCRSession session = MCRServlet.getSession(request);
MCRUserInformation currentUser = session.getUserInformation();
MCRUserInformation apiUser = MCRUserManager.getUser(MCRJSONWebTokenUtil.retrieveUsernameFromAuthenticationToken(signedJWT));
session.setUserInformation(apiUser);
MCRObject mcrObj = MCRMetadataManager.retrieveMCRObject(mcrObjIDObj);
MCRObjectID derID = null;
if (overwriteOnExistingLabel) {
for (MCRMetaLinkID derLink : mcrObj.getStructure().getDerivates()) {
if (label.equals(derLink.getXLinkLabel()) || label.equals(derLink.getXLinkTitle())) {
derID = derLink.getXLinkHrefID();
}
}
}
if (derID == null) {
derID = MCRObjectID.getNextFreeId(mcrObjIDObj.getProjectId() + "_derivate");
MCRDerivate mcrDerivate = new MCRDerivate();
mcrDerivate.setLabel(label);
mcrDerivate.setId(derID);
mcrDerivate.setSchema("datamodel-derivate.xsd");
mcrDerivate.getDerivate().setLinkMeta(new MCRMetaLinkID("linkmeta", mcrObjIDObj, null, null));
mcrDerivate.getDerivate().setInternals(new MCRMetaIFS("internal", UPLOAD_DIR.resolve(derID.toString()).toString()));
MCRMetadataManager.create(mcrDerivate);
MCRMetadataManager.addOrUpdateDerivateToObject(mcrObjIDObj, new MCRMetaLinkID("derobject", derID, null, label));
}
response = Response.created(info.getBaseUriBuilder().path("v1/objects/" + mcrObjID + "/derivates/" + derID).build()).type("application/xml; charset=UTF-8").header(HEADER_NAME_AUTHORIZATION, MCRJSONWebTokenUtil.createJWTAuthorizationHeader(signedJWT)).build();
session.setUserInformation(currentUser);
} catch (Exception e) {
LOGGER.error("Exeption while uploading derivate", e);
}
return response;
}
use of org.mycore.datamodel.metadata.MCRMetaIFS in project mycore by MyCoRe-Org.
the class MCRBasketPersistence method createNewDerivate.
/**
* Creates a new, empty derivate.
*
* @param ownerID the ID of the object owning the new derivate
* @param derivateOID a free derivate ID to use for the newly created derivate
* @return the empty derivate that was created.
* @throws IOException
* @throws MCRPersistenceException
* @throws MCRAccessException see {@link MCRMetadataManager#create(MCRDerivate)}
*/
private static MCRDerivate createNewDerivate(MCRObjectID ownerID, MCRObjectID derivateOID) throws MCRPersistenceException, IOException, MCRAccessException {
MCRDerivate derivate = new MCRDerivate();
derivate.setId(derivateOID);
derivate.setLabel("Saved basket data for " + ownerID);
String schema = MCRConfiguration.instance().getString("MCR.Metadata.Config.derivate", "datamodel-derivate.xml");
derivate.setSchema(schema.replaceAll(".xml", ".xsd"));
MCRMetaIFS ifs = new MCRMetaIFS();
ifs.setSubTag("internal");
ifs.setSourcePath(null);
derivate.getDerivate().setInternals(ifs);
MCRMetaLinkID linkId = new MCRMetaLinkID();
linkId.setSubTag("linkmeta");
linkId.setReference(ownerID, null, null);
derivate.getDerivate().setLinkMeta(linkId);
MCRMetadataManager.create(derivate);
return derivate;
}
use of org.mycore.datamodel.metadata.MCRMetaIFS in project mycore by MyCoRe-Org.
the class MCRUploadHandlerIFS method createDerivate.
private MCRDerivate createDerivate(MCRObjectID derivateID) throws MCRPersistenceException, IOException, MCRAccessException {
MCRDerivate derivate = new MCRDerivate();
derivate.setId(derivateID);
derivate.setLabel("data object from " + documentID);
String schema = CONFIG.getString("MCR.Metadata.Config.derivate", "datamodel-derivate.xml").replaceAll(".xml", ".xsd");
derivate.setSchema(schema);
MCRMetaLinkID linkId = new MCRMetaLinkID();
linkId.setSubTag("linkmeta");
linkId.setReference(documentID, null, null);
derivate.getDerivate().setLinkMeta(linkId);
MCRMetaIFS ifs = new MCRMetaIFS();
ifs.setSubTag("internal");
ifs.setSourcePath(null);
derivate.getDerivate().setInternals(ifs);
LOGGER.debug("Creating new derivate with ID {}", this.derivateID);
MCRMetadataManager.create(derivate);
setDefaultPermissions(derivateID);
return derivate;
}
use of org.mycore.datamodel.metadata.MCRMetaIFS in project mycore by MyCoRe-Org.
the class MCRSwordUtil method createDerivate.
public static MCRDerivate createDerivate(String documentID) throws MCRPersistenceException, IOException, MCRAccessException {
final String projectId = MCRObjectID.getInstance(documentID).getProjectId();
MCRObjectID oid = MCRObjectID.getNextFreeId(projectId, "derivate");
final String derivateID = oid.toString();
MCRDerivate derivate = new MCRDerivate();
derivate.setId(oid);
derivate.setLabel("data object from " + documentID);
String schema = CONFIG.getString("MCR.Metadata.Config.derivate", "datamodel-derivate.xml").replaceAll(".xml", ".xsd");
derivate.setSchema(schema);
MCRMetaLinkID linkId = new MCRMetaLinkID();
linkId.setSubTag("linkmeta");
linkId.setReference(documentID, null, null);
derivate.getDerivate().setLinkMeta(linkId);
MCRMetaIFS ifs = new MCRMetaIFS();
ifs.setSubTag("internal");
ifs.setSourcePath(null);
derivate.getDerivate().setInternals(ifs);
LOGGER.debug("Creating new derivate with ID {}", derivateID);
MCRMetadataManager.create(derivate);
if (CONFIG.getBoolean("MCR.Access.AddDerivateDefaultRule", true)) {
MCRAccessInterface AI = MCRAccessManager.getAccessImpl();
Collection<String> configuredPermissions = AI.getAccessPermissionsFromConfiguration();
for (String permission : configuredPermissions) {
MCRAccessManager.addRule(derivateID, permission, MCRAccessManager.getTrueRule(), "default derivate rule");
}
}
final MCRPath rootDir = MCRPath.getPath(derivateID, "/");
if (Files.notExists(rootDir)) {
rootDir.getFileSystem().createRoot(derivateID);
}
return derivate;
}
use of org.mycore.datamodel.metadata.MCRMetaIFS in project mycore by MyCoRe-Org.
the class MCRIFSTest method createDerivate.
public static MCRDerivate createDerivate(MCRObjectID objectHrefId) {
MCRDerivate derivate = new MCRDerivate();
derivate.setId(MCRObjectID.getNextFreeId("mycore_derivate"));
derivate.setSchema("datamodel-derivate.xsd");
MCRMetaIFS ifs = new MCRMetaIFS();
ifs.setSubTag("internal");
ifs.setSourcePath(null);
derivate.getDerivate().setInternals(ifs);
MCRMetaLinkID mcrMetaLinkID = new MCRMetaLinkID();
mcrMetaLinkID.setReference(objectHrefId.toString(), null, null);
derivate.getDerivate().setLinkMeta(mcrMetaLinkID);
return derivate;
}
Aggregations