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(); }
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 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; }