private ArrayList<Attribute> selectAttributes( ManagedObject managedObject, HashMap<String, String> parameters) { ArrayList<Attribute> attributes = managedObject.getAttributes(); ArrayList<Attribute> requestedAttributes = new ArrayList<>(); for (Attribute a : attributes) { if (parameters.containsKey(a.getAttributeName())) { requestedAttributes.add(a); } } return requestedAttributes; }
public void modifyAttribute( String uniqueIdentifier, Attribute attribute, HashMap<String, String> parameters) throws KLMSItemNotFoundException { EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); ManagedObject object = getObjectByUID(uniqueIdentifier, em); ArrayList<Attribute> objectAttributes = object.getAttributes(); for (Attribute attrib : objectAttributes) { if (attrib.getAttributeName().equals(attribute.getAttributeName())) { KLMSAttributeValue[] values = attrib.getValues(); KLMSAttributeValue[] newValues = attribute.getValues(); if (attrib.getAttributeType() == EnumTypeKLMS.Structure) { for (int i = 0; i < values.length; i++) { attrib.setValue(newValues[i].getValueString(), newValues[i].getName()); } } else { attrib.setValue(newValues[0].getValueString(), null); } } } em.getTransaction().commit(); em.clear(); }
public ArrayList<String> getAttributeList( String uniqueIdentifier, HashMap<String, String> parameters) throws KLMSItemNotFoundException { EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); ManagedObject object = getObjectByUID(uniqueIdentifier, em); ArrayList<String> attributeNames = new ArrayList<>(); for (Attribute a : object.getAttributes()) { attributeNames.add(a.getAttributeName()); } em.getTransaction().commit(); em.clear(); return attributeNames; }
public ArrayList<Attribute> locate(ArrayList<Attribute> locateAttributes) { EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); List<ManagedObject> objects = loadAllObjects(em, locateAttributes); ArrayList<Attribute> uids = new ArrayList<>(); for (ManagedObject o : objects) { if (!(o instanceof CryptographicObject && ((CryptographicObject) o).isDestroyed())) { boolean objectLocated = true; ArrayList<Attribute> objectAttributes = o.getAttributes(); for (Attribute locateAttribute : locateAttributes) { boolean attributeLocated = false; for (Attribute objectAttribute : objectAttributes) { if (locateAttribute.equals(objectAttribute)) { attributeLocated = true; break; } } if (!attributeLocated) { objectLocated = false; break; } } if (objectLocated) { uids.add(new UniqueIdentifier(o.getUniqueIdentifierValue())); } } } em.getTransaction().commit(); em.clear(); return uids; }