use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCREventHandlerBase method doHandleEvent.
/**
* This method handle all calls for EventHandler for the event types
* MCRObject, MCRDerivate and MCRFile.
*
* @param evt
* The MCREvent object
*/
public void doHandleEvent(MCREvent evt) {
if (evt.getObjectType().equals(MCREvent.OBJECT_TYPE)) {
MCRObject obj = (MCRObject) evt.get("object");
if (obj != null) {
logger.debug("{} handling {} {}", getClass().getName(), obj.getId(), evt.getEventType());
switch(evt.getEventType()) {
case MCREvent.CREATE_EVENT:
handleObjectCreated(evt, obj);
break;
case MCREvent.UPDATE_EVENT:
handleObjectUpdated(evt, obj);
break;
case MCREvent.DELETE_EVENT:
handleObjectDeleted(evt, obj);
break;
case MCREvent.REPAIR_EVENT:
handleObjectRepaired(evt, obj);
break;
case MCREvent.INDEX_EVENT:
handleObjectIndex(evt, obj);
break;
default:
logger.warn("Can't find method for an object data handler for event type {}", evt.getEventType());
break;
}
return;
}
logger.warn("Can't find method for " + MCREvent.OBJECT_TYPE + " for event type {}", evt.getEventType());
return;
}
if (evt.getObjectType().equals(MCREvent.DERIVATE_TYPE)) {
MCRDerivate der = (MCRDerivate) evt.get("derivate");
if (der != null) {
logger.debug("{} handling {} {}", getClass().getName(), der.getId(), evt.getEventType());
switch(evt.getEventType()) {
case MCREvent.CREATE_EVENT:
handleDerivateCreated(evt, der);
break;
case MCREvent.UPDATE_EVENT:
handleDerivateUpdated(evt, der);
break;
case MCREvent.DELETE_EVENT:
handleDerivateDeleted(evt, der);
break;
case MCREvent.REPAIR_EVENT:
handleDerivateRepaired(evt, der);
break;
case MCREvent.INDEX_EVENT:
updateDerivateFileIndex(evt, der);
break;
default:
logger.warn("Can't find method for a derivate data handler for event type {}", evt.getEventType());
break;
}
return;
}
logger.warn("Can't find method for " + MCREvent.DERIVATE_TYPE + " for event type {}", evt.getEventType());
return;
}
if (evt.getObjectType().equals(MCREvent.PATH_TYPE)) {
Path path = (Path) evt.get(MCREvent.PATH_KEY);
if (path != null) {
if (!path.isAbsolute()) {
logger.warn("Cannot handle path events on non absolute paths: {}", path);
}
logger.debug("{} handling {} {}", getClass().getName(), path, evt.getEventType());
BasicFileAttributes attrs = (BasicFileAttributes) evt.get(MCREvent.FILEATTR_KEY);
if (attrs == null && !evt.getEventType().equals(MCREvent.DELETE_EVENT)) {
logger.warn("BasicFileAttributes for {} was not given. Resolving now.", path);
try {
attrs = Files.getFileAttributeView(path, BasicFileAttributeView.class).readAttributes();
} catch (IOException e) {
logger.error("Could not get BasicFileAttributes from path: {}", path, e);
}
}
switch(evt.getEventType()) {
case MCREvent.CREATE_EVENT:
handlePathCreated(evt, path, attrs);
break;
case MCREvent.UPDATE_EVENT:
handlePathUpdated(evt, path, attrs);
break;
case MCREvent.DELETE_EVENT:
handlePathDeleted(evt, path, attrs);
break;
case MCREvent.REPAIR_EVENT:
handlePathRepaired(evt, path, attrs);
break;
case MCREvent.INDEX_EVENT:
updatePathIndex(evt, path, attrs);
break;
default:
logger.warn("Can't find method for Path data handler for event type {}", evt.getEventType());
break;
}
return;
}
logger.warn("Can't find method for " + MCREvent.PATH_TYPE + " for event type {}", evt.getEventType());
return;
}
if (evt.getObjectType().equals(MCREvent.CLASS_TYPE)) {
MCRCategory cl = (MCRCategory) evt.get("class");
if (cl != null) {
logger.debug("{} handling {} {}", getClass().getName(), cl.getId(), evt.getEventType());
switch(evt.getEventType()) {
case MCREvent.CREATE_EVENT:
handleClassificationCreated(evt, cl);
break;
case MCREvent.UPDATE_EVENT:
handleClassificationUpdated(evt, cl);
break;
case MCREvent.DELETE_EVENT:
handleClassificationDeleted(evt, cl);
break;
case MCREvent.REPAIR_EVENT:
handleClassificationRepaired(evt, cl);
break;
default:
logger.warn("Can't find method for a classification data handler for event type {}", evt.getEventType());
break;
}
return;
}
logger.warn("Can't find method for " + MCREvent.CLASS_TYPE + " for event type {}", evt.getEventType());
}
}
use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCRAuthorityWithURI method lookupCategoryID.
@Override
protected MCRCategoryID lookupCategoryID() {
for (MCRCategory category : getCategoryByURI(valueURI)) {
if (authorityURI.equals(category.getRoot().getLabel(LABEL_LANG_URI).get().getText())) {
return category.getId();
}
}
// maybe valueUri is in form {authorityURI}#{categId}
if (valueURI.startsWith(authorityURI) && authorityURI.length() < valueURI.length()) {
String categId;
try {
categId = valueURI.substring(authorityURI.length() + 1);
} catch (RuntimeException e) {
LOGGER.warn("authorityURI:{}, valueURI:{}", authorityURI, valueURI);
throw e;
}
int internalStylePos = authorityURI.indexOf(CLASS_URI_PART);
if (internalStylePos > 0) {
String rootId = authorityURI.substring(internalStylePos + CLASS_URI_PART.length());
MCRCategoryID catId = new MCRCategoryID(rootId, categId);
if (DAO.exist(catId)) {
return catId;
}
}
return getCategoryByURI(authorityURI).stream().map(cat -> new MCRCategoryID(cat.getId().getRootID(), categId)).filter(DAO::exist).findFirst().orElse(null);
}
return null;
}
use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCRAccessCondition method lookupCategoryID.
/* (non-Javadoc)
* @see org.mycore.mods.classification.MCRAuthorityInfo#lookupCategoryID()
*/
@Override
protected MCRCategoryID lookupCategoryID() {
Collection<MCRCategory> categoryByURI = MCRAuthorityWithURI.getCategoryByURI(href);
if (categoryByURI.size() > 1) {
throw new MCRException(href + " is ambigous: " + categoryByURI.stream().map(MCRCategory::getId).collect(Collectors.toList()));
}
if (!categoryByURI.isEmpty()) {
return categoryByURI.iterator().next().getId();
}
// maybe href is in form {authorityURI}#{categId}
String categId, authorityURI = null;
try {
authorityURI = href.substring(0, href.lastIndexOf("#"));
categId = href.substring(authorityURI.length() + 1);
} catch (RuntimeException e) {
LOGGER.warn("authorityURI:{}, valueURI:{}", authorityURI, href);
return null;
}
int internalStylePos = authorityURI.indexOf(MCRAuthorityWithURI.CLASS_URI_PART);
if (internalStylePos > 0) {
String rootId = authorityURI.substring(internalStylePos + MCRAuthorityWithURI.CLASS_URI_PART.length());
MCRCategoryID catId = new MCRCategoryID(rootId, categId);
if (DAO.exist(catId)) {
return catId;
}
}
Collection<MCRCategory> classes = MCRAuthorityWithURI.getCategoryByURI(authorityURI);
return classes.stream().map(cat -> new MCRCategoryID(cat.getId().getRootID(), categId)).filter(DAO::exist).findFirst().orElse(null);
}
use of org.mycore.datamodel.classifications2.MCRCategory 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 "";
}
}
use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCRXMLFunctions method isCategoryID.
/**
* @param classificationId
* @param categoryId
* @return
*/
public static boolean isCategoryID(String classificationId, String categoryId) {
MCRCategory category = null;
try {
MCRCategoryID categID = MCRCategoryID.fromString(classificationId + ":" + categoryId);
MCRCategoryDAO dao = MCRCategoryDAOFactory.getInstance();
category = dao.getCategory(categID, 0);
} catch (Throwable e) {
LOGGER.error("Could not determine state for classification id {} and category id {}", classificationId, categoryId, e);
}
return category != null;
}
Aggregations