public static List<ClassificationType> getClassifications(RegistryObjectType ro, String scheme) { List<ClassificationType> result = new ArrayList<ClassificationType>(); List<ClassificationType> classifications = ro.getClassification(); for (int i = 0, len = classifications.size() ; i < len ; i++) { if (classifications.get(i).getClassificationScheme().equals(scheme)) { result.add(classifications.get(i)); } } return result; }
public XDSCode getXDSCode(ClassificationType clType, boolean createMissing) throws XDSException { String scheme = clType.getClassificationScheme(); String codeValue = clType.getNodeRepresentation(); String codeDesignator = clType.getSlot().get(0).getValueList().getValue().get(0); if (!createMissing) { if (!adCodes.isClassSchemeCodeDefined(scheme, codeValue, codeDesignator)) { throw new XDSException(XDSException.XDS_ERR_REGISTRY_METADATA_ERROR, "Unknown code:"+ codeValue+"^^"+codeDesignator+" ("+scheme+")", null); } } XDSCode code = new XDSCode(codeValue, codeDesignator, clType.getName().getLocalizedString().get(0).getValue(), scheme); try { return (XDSCode) em.createNamedQuery(XDSCode.FIND_BY_CODE_VALUE) .setParameter(1, codeValue) .setParameter(2, codeDesignator) .setParameter(3, scheme) .getSingleResult(); } catch (NoResultException x) { log.info("Store new XDS Code! code:"+code); em.persist(code); return code; } }
private static void checkCodes(RegistryObjectType roType, List<String> requiredCodes) throws XDSException { List<ClassificationType> clList = roType.getClassification(); String objId = roType.getId(); for (ClassificationType cl : clList) { if( objId.equals(cl.getClassifiedObject())) { if (requiredCodes.remove(cl.getClassificationScheme())) { if (cl.getName() == null || cl.getName().getLocalizedString() == null || cl.getName().getLocalizedString().isEmpty()) { throw new XDSException(XDSException.XDS_ERR_REGISTRY_METADATA_ERROR, "Missing code display name in code '"+cl.getNodeRepresentation()+ "(code classification:"+cl.getClassificationScheme(), null); } } } } if (requiredCodes.size() > 0) throw new XDSException(XDSException.XDS_ERR_REGISTRY_METADATA_ERROR, "Missing code values in '"+objId+"'! codes:"+requiredCodes, null); }
toPersistenceObj(clType, cl); cl.setNodeRepresentation(clType.getNodeRepresentation()); log.debug("######clType.getClassificationScheme:{}",clType.getClassificationScheme()); if (clType.getClassificationScheme() != null) { RegistryObject obj = getRegistryObject(clType.getClassificationScheme()); if (obj == null) { throw new XDSException(XDSException.XDS_ERR_REGISTRY_ERROR, "Classification Scheme ("+clType.getClassificationScheme()+ ") missing! Classification id:"+clType.getId(), null); } else if (obj instanceof ClassificationScheme) { } else { throw new XDSException(XDSException.XDS_ERR_REGISTRY_ERROR, "Referenced ClassificationScheme ("+clType.getClassificationScheme()+ ") is not a ClassificationScheme! (objType:"+obj.getObjectType()+", class:"+obj.getClass().getSimpleName()+ ") Classification id:"+clType.getId(), null); } else { throw new XDSException(XDSException.XDS_ERR_REGISTRY_ERROR, "Referenced ClassificationNode ("+clType.getClassificationScheme()+ ") is not a ClassificationNode! (objType:"+obj.getObjectType()+", class:"+obj.getClass().getSimpleName()+ ") Classification id:"+clType.getId(), null);