use of org.mycore.datamodel.classifications2.MCRCategoryDAO 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.MCRCategoryDAO in project mycore by MyCoRe-Org.
the class MCRClassificationUtils method fromStream.
/**
* Imports a classification from the given input stream. If the classification
* already exists, it will be replaced.
*
* @param inputStream the classification stream
* @throws MCRException xml parsing went wrong
* @throws SAXParseException xml parsing went wrong
* @throws URISyntaxException unable to transform the xml to a {@link MCRCategory}
* @throws MCRAccessException you are not allowed to import the classification
*/
public static void fromStream(InputStream inputStream) throws MCRException, SAXParseException, URISyntaxException, MCRAccessException {
MCRCategoryDAO DAO = MCRCategoryDAOFactory.getInstance();
Document jdom = MCRXMLParserFactory.getParser().parseXML(new MCRStreamContent(inputStream));
MCRCategory classification = MCRXMLTransformer.getCategory(jdom);
if (DAO.exist(classification.getId())) {
if (!MCRAccessManager.checkPermission(classification.getId().getRootID(), PERMISSION_WRITE)) {
throw MCRAccessException.missingPermission("update classification " + classification.getId().getRootID(), classification.getId().getRootID(), PERMISSION_WRITE);
}
DAO.replaceCategory(classification);
} else {
if (!MCRAccessManager.checkPermission(CREATE_CLASS_PERMISSION)) {
throw MCRAccessException.missingPermission("create classification " + classification.getId().getRootID(), classification.getId().getRootID(), CREATE_CLASS_PERMISSION);
}
DAO.addCategory(null, classification);
}
}
use of org.mycore.datamodel.classifications2.MCRCategoryDAO in project mycore by MyCoRe-Org.
the class MCRUserTestCase method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
MCRCategory groupsCategory = MCRCategoryDAOImplTest.loadClassificationResource("/mcr-roles.xml");
MCRCategoryDAO DAO = MCRCategoryDAOFactory.getInstance();
DAO.addCategory(null, groupsCategory);
}
use of org.mycore.datamodel.classifications2.MCRCategoryDAO in project mycore by MyCoRe-Org.
the class MCRSolrClassificationUtil method rebuildIndex.
/**
* Reindex the whole classification system.
*/
public static void rebuildIndex() {
LOGGER.info("rebuild classification index...");
// categories
MCRCategoryDAO categoryDAO = MCRCategoryDAOFactory.getInstance();
List<MCRCategoryID> rootCategoryIDs = categoryDAO.getRootCategoryIDs();
for (MCRCategoryID rootID : rootCategoryIDs) {
LOGGER.info("rebuild classification '{}'...", rootID);
MCRCategory rootCategory = categoryDAO.getCategory(rootID, -1);
List<MCRCategory> categoryList = getDescendants(rootCategory);
categoryList.add(rootCategory);
List<SolrInputDocument> solrDocumentList = toSolrDocument(categoryList);
bulkIndex(solrDocumentList);
}
// links
MCRCategLinkService linkService = MCRCategLinkServiceFactory.getInstance();
Collection<String> linkTypes = linkService.getTypes();
for (String linkType : linkTypes) {
LOGGER.info("rebuild '{}' links...", linkType);
bulkIndex(linkService.getLinks(linkType).stream().map(link -> new MCRSolrCategoryLink(link.getCategory().getId(), link.getObjectReference())).map(MCRSolrCategoryLink::toSolrDocument).collect(Collectors.toList()));
}
}
use of org.mycore.datamodel.classifications2.MCRCategoryDAO in project mycore by MyCoRe-Org.
the class MCRXMLFunctions method getDisplayName.
/**
* @param classificationId
* @param categoryId
* @return
*/
public static String getDisplayName(String classificationId, String categoryId) {
try {
MCRCategoryID categID = new MCRCategoryID(classificationId, categoryId);
MCRCategoryDAO dao = MCRCategoryDAOFactory.getInstance();
MCRCategory category = dao.getCategory(categID, 0);
return Optional.ofNullable(category).map(MCRCategory::getCurrentLabel).filter(Optional::isPresent).map(Optional::get).map(MCRLabel::getText).orElse("");
} catch (Throwable e) {
LOGGER.error("Could not determine display name for classification id {} and category id {}", classificationId, categoryId, e);
return "";
}
}
Aggregations