use of org.mycore.datamodel.classifications2.MCRLabel in project mycore by MyCoRe-Org.
the class MCRCategoryTypeAdapter method serialize.
@Override
public JsonElement serialize(MCRJSONCategory category, Type arg1, JsonSerializationContext contextSerialization) {
JsonObject rubricJsonObject = new JsonObject();
MCRCategoryID id = category.getId();
if (id != null) {
rubricJsonObject.add(ID, contextSerialization.serialize(id));
}
Set<MCRLabel> labels = category.getLabels();
rubricJsonObject.add(LABELS, contextSerialization.serialize(new MCRLabelSetWrapper(labels)));
URI uri = category.getURI();
if (uri != null) {
rubricJsonObject.addProperty(URISTR, uri.toString());
}
if (category.hasChildren()) {
List<MCRCategory> children = category.getChildren();
Map<MCRCategoryID, Boolean> linkMap = getLinkService().hasLinks(category);
if (linkMap.values().contains(true)) {
rubricJsonObject.addProperty(HASLINK, true);
}
rubricJsonObject.add(CHILDREN, contextSerialization.serialize(new MCRCategoryListWrapper(children, linkMap)));
}
return rubricJsonObject;
}
use of org.mycore.datamodel.classifications2.MCRLabel in project mycore by MyCoRe-Org.
the class MCRLabelSetTypeAdapter method labelsToJsonArray.
private JsonArray labelsToJsonArray(Set<MCRLabel> labels) {
JsonArray labelJsonArray = new JsonArray();
for (MCRLabel label : labels) {
JsonObject labelJsonObj = labelToJsonObj(label);
labelJsonArray.add(labelJsonObj);
}
return labelJsonArray;
}
use of org.mycore.datamodel.classifications2.MCRLabel in project mycore by MyCoRe-Org.
the class MCRClassMapper method getAuthority.
private static String getAuthority(String rootID) {
long classLastModified = Math.max(0, DAO.getLastModified(rootID));
String auth = authCache.getIfUpToDate(rootID, classLastModified);
if (auth == null) {
MCRCategory rootCategory = DAO.getRootCategory(MCRCategoryID.rootID(rootID), 0);
auth = rootCategory.getLabel("x-auth").map(MCRLabel::getText).orElse("");
authCache.put(rootID, auth, classLastModified);
}
return auth.isEmpty() ? null : auth;
}
use of org.mycore.datamodel.classifications2.MCRLabel 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.MCRLabel in project mycore by MyCoRe-Org.
the class MCRClassification2Commands method repairEmptyLabels.
@MCRCommand(syntax = "repair category with empty labels", help = "fixes all categories with no labels (adds a label with categid as @text for default lang)", order = 110)
public static void repairEmptyLabels() {
Session session = MCRHIBConnection.instance().getSession();
String deleteEmptyLabels = "delete from {h-schema}MCRCategoryLabels where text is null or trim(text) = ''";
int affected = session.createNativeQuery(deleteEmptyLabels).executeUpdate();
LOGGER.info("Deleted {} labels.", affected);
String sqlQuery = "select cat.classid,cat.categid from {h-schema}MCRCategory cat left outer join {h-schema}MCRCategoryLabels label on cat.internalid = label.category where label.text is null";
@SuppressWarnings("unchecked") List<Object[]> list = session.createNativeQuery(sqlQuery).getResultList();
for (Object resultList : list) {
Object[] arrayOfResults = (Object[]) resultList;
String classIDString = (String) arrayOfResults[0];
String categIDString = (String) arrayOfResults[1];
MCRCategoryID mcrCategID = new MCRCategoryID(classIDString, categIDString);
MCRLabel mcrCategLabel = new MCRLabel(MCRConstants.DEFAULT_LANG, categIDString, null);
MCRCategoryDAOFactory.getInstance().setLabel(mcrCategID, mcrCategLabel);
LOGGER.info("fixing category with class ID \"{}\" and category ID \"{}\"", classIDString, categIDString);
}
LOGGER.info("Fixing category labels completed!");
}
Aggregations