Esempio n. 1
0
  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();
  }
Esempio n. 2
0
  public void getUsageAllocation(String uniqueIdentifier, UsageLimits usageLimits)
      throws KLMSItemNotFoundException, KLMSPermissionDeniedException {
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();

    ManagedObject object = getObjectByUID(uniqueIdentifier, em);
    object.getUsageAllocation(usageLimits);

    em.getTransaction().commit();
    em.clear();
  }
Esempio n. 3
0
  public ArrayList<Attribute> obtainLease(String uniqueIdentifier)
      throws KLMSPermissionDeniedException, KLMSObjectArchivedException, KLMSItemNotFoundException {
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();

    ManagedObject object = getObjectByUID(uniqueIdentifier, em);
    ArrayList<Attribute> attributes = object.obtainLease();

    em.getTransaction().commit();
    em.clear();

    return attributes;
  }
Esempio n. 4
0
  public ArrayList<Attribute> check(String uniqueIdentifier, ArrayList<Attribute> attributes)
      throws KLMSItemNotFoundException, KLMSIllegalOperationException {
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();

    ManagedObject object = getObjectByUID(uniqueIdentifier, em);
    ArrayList<Attribute> returnAttributes = object.check(attributes);

    em.getTransaction().commit();
    em.clear();

    return returnAttributes;
  }
Esempio n. 5
0
  // Only for Use Case 9.2
  public void forceActivate(String uniqueIdentifier) {
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();

    try {
      ManagedObject object = getObjectByUID(uniqueIdentifier, em);
      object.addAttribute(new State(Integer.toString(EnumState.Active)));
    } catch (Exception e) {

    }

    em.getTransaction().commit();
    em.clear();
  }
Esempio n. 6
0
  public Attribute deleteAttribute(
      String uniqueIdentifier, Attribute attribute, HashMap<String, String> parameters)
      throws KLMSItemNotFoundException {
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();

    ManagedObject object = getObjectByUID(uniqueIdentifier, em);
    Attribute a = object.removeAttribute(attribute);

    em.getTransaction().commit();
    em.clear();

    return a;
  }
Esempio n. 7
0
  public ArrayList<Attribute> addAttribute(
      String uniqueIdentifier,
      ArrayList<Attribute> requestAttributes,
      HashMap<String, String> parameters)
      throws KLMSItemNotFoundException {
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();

    ManagedObject object = getObjectByUID(uniqueIdentifier, em);
    for (Attribute attrib : requestAttributes) {
      object.addAttribute(attrib);
    }

    em.getTransaction().commit();
    em.clear();
    return requestAttributes;
  }
Esempio n. 8
0
  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;
  }
Esempio n. 9
0
  public ManagedObject get(String uniqueIdentifier, HashMap<String, String> parameters)
      throws KLMSItemNotFoundException, KLMSObjectArchivedException {
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();

    ManagedObject object = getObjectByUID(uniqueIdentifier, em);
    object.checkArchiveStatus();

    em.getTransaction().commit();
    em.clear();

    if (object instanceof CryptographicObject && ((CryptographicObject) object).isDestroyed()) {
      throw new KLMSItemNotFoundException(uniqueIdentifier);
    } else {
      return object;
    }
  }
Esempio n. 10
0
  public String destroy(String uniqueIdentifier) throws KLMSItemNotFoundException {
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();

    ManagedObject object = getObjectByUID(uniqueIdentifier, em);

    if (object instanceof CryptographicObject) {
      ((CryptographicObject) object).destroy();
    } else {
      em.remove(object);
    }

    em.getTransaction().commit();
    em.clear();

    return object.getUniqueIdentifierValue();
  }
Esempio n. 11
0
 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;
 }
Esempio n. 12
0
  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;
  }