use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRCategoryTypeAdapter method deserialize.
@Override
public MCRJSONCategory deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject categJsonObject = json.getAsJsonObject();
MCRJSONCategory deserializedCateg = new MCRJSONCategory();
JsonElement idJsonElement = categJsonObject.get(ID);
if (idJsonElement != null) {
MCRCategoryID id = context.deserialize(idJsonElement, MCRCategoryID.class);
deserializedCateg.setId(id);
}
JsonElement parentIdJsonElement = categJsonObject.get(PARENTID);
if (parentIdJsonElement != null) {
MCRCategoryID parentId = context.deserialize(parentIdJsonElement, MCRCategoryID.class);
deserializedCateg.setParentID(parentId);
}
JsonElement positionJsonElem = categJsonObject.get(POSITION);
if (positionJsonElem != null) {
deserializedCateg.setPositionInParent(positionJsonElem.getAsInt());
}
JsonElement labelSetWrapperElem = categJsonObject.get(LABELS);
if (labelSetWrapperElem != null) {
MCRLabelSetWrapper labelSetWrapper = context.deserialize(labelSetWrapperElem, MCRLabelSetWrapper.class);
deserializedCateg.setLabels(labelSetWrapper.getSet());
}
JsonElement uriJsonElement = categJsonObject.get(URISTR);
if (uriJsonElement != null) {
String uriStr = uriJsonElement.getAsString();
deserializedCateg.setURI(URI.create(uriStr));
}
return deserializedCateg;
}
use of org.mycore.datamodel.classifications2.MCRCategoryID 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.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRMODSWrapper method getMcrCategoryIDs.
public List<MCRCategoryID> getMcrCategoryIDs() {
final List<Element> categoryNodes = getCategoryNodes();
final List<MCRCategoryID> categories = new ArrayList<>(categoryNodes.size());
for (Element node : categoryNodes) {
final MCRCategoryID categoryID = MCRClassMapper.getCategoryID(node);
if (categoryID != null) {
categories.add(categoryID);
}
}
return categories;
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRMODSClassificationSupport method getMCRClassNodes.
public static NodeList getMCRClassNodes(final NodeList sources) {
if (sources.getLength() == 0) {
LOGGER.warn("Cannot get first element of node list 'sources'.");
return null;
}
DocumentBuilder documentBuilder = MCRDOMUtils.getDocumentBuilderUnchecked();
try {
final Document document = documentBuilder.newDocument();
final Element source = (Element) sources.item(0);
MCRCategoryID category = MCRClassMapper.getCategoryID(source);
if (category == null) {
return null;
}
final Element returns = document.createElement("returns");
returns.setAttributeNS(MCRConstants.MCR_NAMESPACE.getURI(), "mcr:categId", category.toString());
return returns.getChildNodes();
} catch (Throwable e) {
LOGGER.warn("Error in Xalan Extension", e);
return null;
} finally {
MCRDOMUtils.releaseDocumentBuilder(documentBuilder);
}
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRMODSClassificationSupport method getClassNodes.
/**
* For a category ID, looks up the authority information for that category and returns the attributes in the given
* MODS element so that it represents that category. This is used as a Xalan extension.
*/
public static NodeList getClassNodes(final NodeList sources) {
if (sources.getLength() == 0) {
LOGGER.warn("Cannot get first element of node list 'sources'.");
return null;
}
DocumentBuilder documentBuilder = MCRDOMUtils.getDocumentBuilderUnchecked();
try {
Document document = documentBuilder.newDocument();
final Element source = (Element) sources.item(0);
final String categId = source.getAttributeNS(MCRConstants.MCR_NAMESPACE.getURI(), "categId");
final MCRCategoryID categoryID = MCRCategoryID.fromString(categId);
final Element returns = document.createElementNS(source.getNamespaceURI(), source.getLocalName());
MCRClassMapper.assignCategory(returns, categoryID);
return returns.getChildNodes();
} catch (Throwable e) {
LOGGER.warn("Error in Xalan Extension", e);
return null;
} finally {
MCRDOMUtils.releaseDocumentBuilder(documentBuilder);
}
}
Aggregations