use of org.mycore.datamodel.classifications2.MCRCategLinkReference in project mycore by MyCoRe-Org.
the class MCRSolrFileIndexBaseAccumulator method accumulate.
@Override
public void accumulate(SolrInputDocument doc, Path input, BasicFileAttributes attr) throws IOException {
doc.setField("id", input.toUri().toString());
String absolutePath = '/' + input.subpath(0, input.getNameCount()).toString();
try {
// check if this is an MCRPath -> more metadata
MCRPath mcrPath = MCRPath.toMCRPath(input);
MCRObjectID mcrObjID = MCRMetadataManager.getObjectId(MCRObjectID.getInstance(mcrPath.getOwner()), 10, TimeUnit.SECONDS);
if (mcrObjID == null) {
LOGGER.warn("Could not determine MCRObject for file {}", absolutePath);
doc.setField("returnId", mcrPath.getOwner());
} else {
doc.setField("returnId", mcrObjID.toString());
doc.setField("objectProject", mcrObjID.getProjectId());
}
String ownerID = mcrPath.getOwner();
doc.setField("derivateID", ownerID);
doc.setField("derivateModified", getDerivateModified(ownerID));
Collection<MCRCategoryID> linksFromReference = MCRCategLinkServiceFactory.getInstance().getLinksFromReference(new MCRCategLinkReference(mcrPath));
HashSet<MCRCategoryID> linkedCategories = new HashSet<>(linksFromReference);
for (MCRCategoryID category : linksFromReference) {
for (MCRCategory parent : CATEGORY_DAO.getParents(category)) {
linkedCategories.add(parent.getId());
}
}
for (MCRCategoryID category : linkedCategories) {
doc.addField("fileCategory", category.toString());
}
} catch (ProviderMismatchException e) {
LOGGER.warn("Cannot build all fields as input is not an instance of MCRPath: {}", input);
}
doc.setField("objectType", "data_file");
doc.setField("fileName", input.getFileName().toString());
doc.setField("filePath", absolutePath);
doc.setField("stream_size", attr.size());
doc.setField("stream_name", absolutePath);
doc.setField("stream_source_info", input.toString());
doc.setField("stream_content_type", MCRContentTypes.probeContentType(input));
doc.setField("extension", Files.getFileExtension(input.getFileName().toString()));
MCRISO8601Date iDate = new MCRISO8601Date();
iDate.setDate(new Date(attr.lastModifiedTime().toMillis()));
doc.setField("modified", iDate.getISOString());
}
use of org.mycore.datamodel.classifications2.MCRCategLinkReference in project mycore by MyCoRe-Org.
the class MCRPathXML method getFileXML.
/**
* Returns metadata of the file retrievable by 'path' in XML form.
*
* @param path
* Path to File
* @param attrs
* file attributes of given file
*/
public static Document getFileXML(MCRPath path, BasicFileAttributes attrs) throws IOException {
Element root = new Element("file");
root.setAttribute("uri", path.toUri().toString());
root.setAttribute("ownerID", path.getOwner());
String fileName = path.getFileName().toString();
root.setAttribute("name", fileName);
String absolutePath = path.getOwnerRelativePath();
root.setAttribute("path", absolutePath);
root.setAttribute("extension", getFileExtension(fileName));
root.setAttribute("returnId", MCRMetadataManager.getObjectId(MCRObjectID.getInstance(path.getOwner()), 10, TimeUnit.SECONDS).toString());
Collection<MCRCategoryID> linksFromReference = MCRCategLinkServiceFactory.getInstance().getLinksFromReference(new MCRCategLinkReference(path));
for (MCRCategoryID category : linksFromReference) {
Element catEl = new Element("category");
catEl.setAttribute("id", category.toString());
root.addContent(catEl);
}
if (!attrs.isDirectory() && attrs instanceof MCRFileAttributes<?>) {
addAttributes(root, (MCRFileAttributes<?>) attrs, path);
} else {
addBasicAttributes(root, attrs, path);
}
return new Document(root);
}
use of org.mycore.datamodel.classifications2.MCRCategLinkReference in project mycore by MyCoRe-Org.
the class MCRURLRetriever method getURLforID.
public static String getURLforID(String action, String mcrID, boolean absolute) {
final MCRObjectID objID = MCRObjectID.getInstance(mcrID);
String collectionName = MCRClassificationUtils.getCollection(mcrID);
return getURL(action, collectionName, new MCRCategLinkReference(objID), absolute);
}
use of org.mycore.datamodel.classifications2.MCRCategLinkReference in project mycore by MyCoRe-Org.
the class MCRCategLinkServiceImpl method deleteLinks.
@Override
public void deleteLinks(final Collection<MCRCategLinkReference> ids) {
if (ids.isEmpty()) {
return;
}
HashMap<String, Collection<String>> typeMap = new HashMap<>();
// prepare
Collection<String> objectIds = new LinkedList<>();
String currentType = ids.iterator().next().getType();
typeMap.put(currentType, objectIds);
// collect per type
for (MCRCategLinkReference ref : ids) {
if (!currentType.equals(ref.getType())) {
currentType = ref.getType();
objectIds = typeMap.computeIfAbsent(ref.getType(), k -> new LinkedList<>());
}
objectIds.add(ref.getObjectID());
}
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
javax.persistence.Query q = em.createNamedQuery(NAMED_QUERY_NAMESPACE + "deleteByObjectCollection");
int deleted = 0;
for (Map.Entry<String, Collection<String>> entry : typeMap.entrySet()) {
q.setParameter("ids", entry.getValue());
q.setParameter("type", entry.getKey());
deleted += q.executeUpdate();
}
LOGGER.debug("Number of Links deleted: {}", deleted);
}
use of org.mycore.datamodel.classifications2.MCRCategLinkReference in project mycore by MyCoRe-Org.
the class MCRCategLinkServiceImpl method getReferences.
@Override
public Collection<MCRCategLinkReference> getReferences(String type) {
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<MCRCategLinkReference> query = cb.createQuery(MCRCategLinkReference.class);
Root<MCRCategoryLinkImpl> li = query.from(LINK_CLASS);
Path<MCRCategLinkReference> objectReferencePath = li.get(MCRCategoryLinkImpl_.objectReference);
return em.createQuery(query.select(objectReferencePath).where(cb.equal(objectReferencePath.get(MCRCategLinkReference_.type), type))).setHint(QueryHints.READ_ONLY, "true").getResultList();
}
Aggregations