/**
   * Unlock a Content Relation for other user access.
   *
   * @param id Objid of Content Relation
   * @param param XML TaskParam
   * @return Result XML data structure
   * @throws ContentRelationNotFoundException e
   * @throws LockingException e
   * @throws InvalidContentException e
   * @throws MissingMethodParameterException e
   * @throws SystemException e
   * @throws OptimisticLockingException e
   * @throws InvalidStatusException Thrown if resource is not locked.
   */
  @Override
  public String unlock(final String id, final String param)
      throws ContentRelationNotFoundException, LockingException, MissingMethodParameterException,
          SystemException, OptimisticLockingException, InvalidContentException,
          InvalidStatusException, XmlCorruptedException {

    final ContentRelationCreate cr = setContentRelation(id);
    final TaskParamHandler taskParameter = XmlUtility.parseTaskParam(param);

    Utility.checkOptimisticLockingCriteria(
        cr.getProperties().getLastModificationDate(),
        taskParameter.getLastModificationDate(),
        "Content relation " + id);
    if (cr.getProperties().isLocked()) {
      lockHandler.unlock(cr.getObjid());

      cr.getProperties().setLockStatus(LockStatus.UNLOCKED);
      cr.getProperties().setLockOwnerId(null);
      cr.getProperties().setLockOwnerId(null);
      cr.getProperties().setLockDate((DateTime) null);
    }

    fireContentRelationModified(cr, this.contentRelationXmlProvider.getContentRelationXml(cr));

    return Utility.prepareReturnXml(cr.getProperties().getLastModificationDate(), null);
  }
  /**
   * Submit the Content Relation.
   *
   * @param id objid of ContentRelation
   * @param param Task parameter
   * @return XML result
   * @throws ContentRelationNotFoundException e
   * @throws LockingException e
   * @throws InvalidStatusException e
   * @throws MissingMethodParameterException e
   * @throws SystemException e
   * @throws OptimisticLockingException e
   * @throws InvalidContentException e
   */
  @Override
  public String submit(final String id, final String param)
      throws ContentRelationNotFoundException, LockingException, InvalidStatusException,
          MissingMethodParameterException, SystemException, OptimisticLockingException,
          InvalidContentException, XmlCorruptedException {

    final ContentRelationCreate cr = setContentRelation(id);
    final TaskParamHandler taskParameter = XmlUtility.parseTaskParam(param);
    checkLocked(cr);

    validateToSubmitStatus(cr);

    // check optimistic locking criteria
    Utility.checkOptimisticLockingCriteria(
        cr.getProperties().getLastModificationDate(),
        taskParameter.getLastModificationDate(),
        "Content relation " + id);

    cr.getProperties().setStatus(StatusType.SUBMITTED);
    // set status comment
    if (taskParameter.getComment() != null) {
      cr.getProperties().setStatusComment(taskParameter.getComment());
    } else {
      cr.getProperties().setStatusComment("Status changed to 'submitted'");
    }

    cr.persistProperties(true);

    // load metadata content to resource
    enrichWithMetadataContent(cr);
    fireContentRelationModified(cr, this.contentRelationXmlProvider.getContentRelationXml(cr));

    return Utility.prepareReturnXml(cr.getProperties().getLastModificationDate(), null);
  }
  /**
   * @param id objid of ContentRelation
   * @param param Task parameter
   * @return XML result
   * @throws ContentRelationNotFoundException e
   * @throws LockingException e
   * @throws InvalidStatusException e
   * @throws MissingMethodParameterException e
   * @throws SystemException e
   * @throws OptimisticLockingException e
   * @throws InvalidContentException e
   */
  @Override
  public String release(final String id, final String param)
      throws ContentRelationNotFoundException, LockingException, InvalidStatusException,
          MissingMethodParameterException, SystemException, OptimisticLockingException,
          InvalidContentException, XmlCorruptedException {

    final ContentRelationCreate cr = setContentRelation(id);
    final TaskParamHandler taskParameter = XmlUtility.parseTaskParam(param);
    checkLocked(cr);
    checkReleased(cr);
    if (cr.getProperties().getStatus() != StatusType.SUBMITTED) {
      throw new InvalidStatusException(
          "The object is not in state '"
              + Constants.STATUS_SUBMITTED
              + "' and can not be "
              + Constants.STATUS_RELEASED
              + '.');
    }
    Utility.checkOptimisticLockingCriteria(
        cr.getProperties().getLastModificationDate(),
        taskParameter.getLastModificationDate(),
        "Content relation " + id);

    cr.getProperties().setStatus(StatusType.RELEASED);

    // set status comment
    if (taskParameter.getComment() != null) {
      cr.getProperties().setStatusComment(taskParameter.getComment());
    } else {
      cr.getProperties().setStatusComment("Status changed to 'released'");
    }

    cr.persistProperties(true);

    // load metadata content to resource
    enrichWithMetadataContent(cr);
    fireContentRelationModified(cr, this.contentRelationXmlProvider.getContentRelationXml(cr));

    return Utility.prepareReturnXml(cr.getProperties().getLastModificationDate(), null);
  }
 /**
  * Prepare the assignment response message.
  *
  * <p>Preconditions: The TripleStore must be in sync with the repository.
  *
  * @param cr content relation
  * @param pid The new assigned PID.
  * @return response message
  * @throws WebserverSystemException Thrown in case of internal error.
  * @throws TripleStoreSystemException Thrown in case of TripleStore error.
  */
 private String prepareResponse(final ContentRelationCreate cr, final String pid) {
   return Utility.prepareReturnXml(
       cr.getProperties().getLastModificationDate(), "<pid>" + pid + "</pid>\n");
 }