use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRMODSClassificationSupport method getClassCategParentLink.
public static String getClassCategParentLink(final NodeList sources) {
if (sources.getLength() == 0) {
LOGGER.warn("Cannot get first element of node list 'sources'.");
return "";
}
final Element source = (Element) sources.item(0);
MCRCategoryID category = MCRClassMapper.getCategoryID(source);
if (category == null) {
return "";
}
String id;
try {
id = MCRXMLFunctions.encodeURIPath(category.getID());
} catch (URISyntaxException e) {
/* This should be impossible! */
throw new MCRException(e);
}
return MessageFormat.format("classification:metadata:0:parents:{0}:{1}", category.getRootID(), id);
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRMODSClassificationSupport method getClassCategLink.
public static String getClassCategLink(final NodeList sources) {
if (sources.getLength() == 0) {
LOGGER.warn("Cannot get first element of node list 'sources'.");
return "";
}
final Element source = (Element) sources.item(0);
MCRCategoryID category = MCRClassMapper.getCategoryID(source);
if (category == null) {
return "";
}
String id;
try {
id = MCRXMLFunctions.encodeURIPath(category.getID());
} catch (URISyntaxException e) {
/* This should be impossible! */
throw new MCRException(e);
}
return MessageFormat.format("classification:metadata:0:children:{0}:{1}", category.getRootID(), id);
}
use of org.mycore.datamodel.classifications2.MCRCategoryID 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.MCRCategoryID 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.MCRCategoryID 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;
}
Aggregations