Exemplo n.º 1
0
  /**
   * Gets the where clause to resolve the current part of the path expression.
   *
   * @param objectId The id of the resource (without version information!) for that the current part
   *     shall be resolved.
   * @param tsu The {@link TripleStoreUtility} to use.
   * @return Returns the where clause.
   * @throws TripleStoreSystemException e
   */
  public StringBuffer getResolveCurrentWhereClause(
      final String objectId, final TripleStoreUtility tsu) throws TripleStoreSystemException {

    // Currently three attributes exist, that needs 'inverse' lookup:
    // item:container and container:container and are stored as a
    // relationship from parent to child. Additionally, object
    // identifier need inverse lookup to get the correct dc identifier.
    // Therefore, these attributes have to be handled in a special
    // way.
    return isInverse()
        ? tsu.getRetrieveWhereClause(
            true, getCacheId(), objectId, null, getContentTypePredicateId(), getContentTypeTitle())
        : tsu.getRetrieveWhereClause(false, getCacheId(), objectId, null, null, null);
  }
  /**
   * resolve attribute assigned-on. check if tail is present and resolvable (dependent on variable
   * SUPPORTED_ASSIGNED_ON_OBJECT_ATTRIBUTES). if tail is not resolvable, mark whole attribute as
   * unresolvable.
   *
   * @param ctx EvaluationContext
   * @param attributeIdValue whole attribute
   * @param resolvableAttribute resolvable part of attribute
   * @param tail tail after resolvable part
   * @return Object[] result
   * @throws de.escidoc.core.common.exceptions.system.WebserverSystemException
   * @throws de.escidoc.core.common.exceptions.application.notfound.GrantNotFoundException
   * @throws de.escidoc.core.common.exceptions.system.TripleStoreSystemException
   * @throws de.escidoc.core.common.exceptions.application.notfound.ResourceNotFoundException
   * @throws de.escidoc.core.common.exceptions.system.SystemException
   */
  private Object[] resolveAssignedOnAttribute(
      final EvaluationCtx ctx,
      final String attributeIdValue,
      final String resolvableAttribute,
      final String tail)
      throws TripleStoreSystemException, SystemException, GrantNotFoundException,
          ResourceNotFoundException, WebserverSystemException {
    EvaluationResult result;
    final String userOrGroupId =
        FinderModuleHelper.retrieveSingleResourceAttribute(ctx, Constants.URI_RESOURCE_ID, true);
    final String grantId =
        FinderModuleHelper.retrieveSingleResourceAttribute(ctx, Constants.URI_SUBRESOURCE_ID, true);
    String assignedOnObjectId;
    if (grantId == null || grantId.length() == 0) {
      // if no grantId is present
      // fetch grant-attribute from invocation-mapping
      try {
        assignedOnObjectId = fetchSingleResourceAttribute(ctx, resolvableAttribute + "-new");
      } catch (final Exception e) {
        // not assigned to an object
        // so mark complete attribute as unresolvable
        result =
            CustomEvaluationResultBuilder.createSingleStringValueResult(
                de.escidoc.core.common.business.Constants.UNRESOLVED_ATTRIBUTE_VALUE);
        return new Object[] {result, attributeIdValue};
      }
    } else {
      final RoleGrant grant =
          resolvableAttribute.matches(".*" + XmlUtility.NAME_USER_ACCOUNT + ".*")
              ? getUserAccountGrant(ctx, userOrGroupId, grantId)
              : getUserGroupGrant(ctx, grantId);
      assertGrant(grantId, grant);
      assignedOnObjectId = grant.getObjectId();
    }
    if (assignedOnObjectId == null) {
      // not assigned on an object
      // so mark complete attribute as unresolvable
      result =
          CustomEvaluationResultBuilder.createSingleStringValueResult(
              de.escidoc.core.common.business.Constants.UNRESOLVED_ATTRIBUTE_VALUE);
      return new Object[] {result, attributeIdValue};
    }

    // check if tailing attribute is resolvable for assigned object-type
    if (tail != null) {
      final String objectType = fetchObjectType(ctx, assignedOnObjectId);
      if (objectType.equals(XmlUtility.NAME_COMPONENT) && tail.equals(XmlUtility.NAME_CONTEXT)) {
        // if we have to resolve the context of a component,
        // we first have to get the itemId and resolve context for
        // the itemId
        final List<String> itemIds =
            FinderModuleHelper.retrieveFromTripleStore(
                true,
                tsu.getRetrieveWhereClause(
                    true, TripleStoreUtility.PROP_COMPONENT, assignedOnObjectId, null, null, null),
                assignedOnObjectId,
                TripleStoreUtility.PROP_COMPONENT,
                this.tsu);
        if (itemIds == null || itemIds.isEmpty() || itemIds.size() != 1) {
          result =
              CustomEvaluationResultBuilder.createResourceNotFoundResult(
                  new ItemNotFoundException(
                      "item for component " + assignedOnObjectId + " not found"));
        } else {
          assignedOnObjectId = itemIds.get(0);
        }
      }
    }
    result = CustomEvaluationResultBuilder.createSingleStringValueResult(assignedOnObjectId);
    return new Object[] {result, resolvableAttribute};
  }