use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCRSolrClassificationUtil method getAncestors.
/**
* Returns a list of all ancestors. The list is ordered. The first element is
* always the root node and the last element is always the parent. If the
* element has no ancestor an empty list is returned.
*
* @return list of ancestors
*/
public static LinkedList<MCRCategory> getAncestors(MCRCategory category) {
LinkedList<MCRCategory> ancestors = new LinkedList<>();
MCRCategory parent = category.getParent();
while (parent != null) {
ancestors.addFirst(parent);
parent = parent.getParent();
}
return ancestors;
}
use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCRSolrClassificationUtil method reindex.
public static void reindex(Collection<MCRCategoryID> categoryIds) {
List<MCRCategory> categoryList = new ArrayList<>(categoryIds.size());
MCRCategoryDAO dao = MCRCategoryDAOFactory.getInstance();
for (MCRCategoryID categoryId : categoryIds) {
MCRCategory category = dao.getCategory(categoryId, 0);
categoryList.add(category);
}
reindex(categoryList.toArray(new MCRCategory[categoryList.size()]));
}
use of org.mycore.datamodel.classifications2.MCRCategory 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.MCRCategory in project mycore by MyCoRe-Org.
the class MCRSolrCategory method toSolrDocument.
public SolrInputDocument toSolrDocument() {
SolrInputDocument doc = new SolrInputDocument();
LinkedList<MCRCategory> ancestors = MCRSolrClassificationUtil.getAncestors(category);
MCRCategory parent = !ancestors.isEmpty() ? ancestors.getLast() : null;
// ids
MCRCategoryID id = category.getId();
doc.setField("id", id.toString());
doc.setField("classification", id.getRootID());
doc.setField("type", "node");
if (category.isCategory()) {
doc.setField("category", id.getID());
}
// labels
Set<MCRLabel> labels = category.getLabels();
for (MCRLabel label : labels) {
doc.addField("label." + label.getLang(), label.getText());
}
// children
if (category.hasChildren()) {
for (MCRCategory child : category.getChildren()) {
doc.addField("children", child.getId().toString());
}
}
// parent
if (parent != null) {
doc.setField("parent", parent.getId().toString());
doc.setField("index", parent.getChildren().indexOf(category));
}
// ancestors
for (MCRCategory ancestor : ancestors) {
doc.addField("ancestors", ancestor.getId().toString());
}
return doc;
}
use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCRSolrCategoryDAO method deleteCategory.
@Override
public void deleteCategory(MCRCategoryID id) {
MCRCategory category = MCRCategoryDAOFactory.getInstance().getCategory(id, 0);
MCRCategory parent = category.getParent();
super.deleteCategory(id);
solrDelete(id, parent);
}
Aggregations