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