Example #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);
  }
  @Override
  public StartElement startElement(final StartElement element)
      throws TripleStoreSystemException, WebserverSystemException, InvalidContentException {
    final String curPath = parser.getCurPath();
    if (curPath.startsWith(this.componentPath) && curPath.equals(this.componentPath)) {
      // do my job
      // save componentId
      final int indexObjid = element.indexOfAttribute(null, "objid");
      final int indexHref = element.indexOfAttribute(Constants.XLINK_NS_URI, "href");
      if (indexObjid >= 0 || indexHref >= 0) {
        final String componentId =
            indexObjid >= 0
                ? element.getAttribute(indexObjid).getValue()
                : Utility.getId(element.getAttribute(indexHref).getValue());

        if (componentId.length() > 0) {
          // check if component exists
          boolean componentExists = false;
          final List<String> existingComponents =
              TripleStoreUtility.getInstance().getComponents(this.itemId);
          for (final String existingComponent : existingComponents) {
            if (existingComponent.equals(componentId)) {
              componentExists = true;
              break;
            }
          }
          if (!componentExists) {
            throw new InvalidContentException(
                "Component with id "
                    + componentId
                    + " does not exist in item "
                    + this.itemId
                    + '.');
          }
        }
      }
    }
    return element;
  }
  /**
   * Fetches the value of the attribute {@code ATTR_USER_OU} for the provided user account.
   *
   * @param userAccount The user account to fetch the value from.
   * @param getChildren if also children of userAccountous are to be fetched.
   * @return Returns the attribute value in an {@code EvaluationResult}.
   * @throws de.escidoc.core.common.exceptions.system.SystemException
   */
  private EvaluationResult fetchUserAccountOus(
      final UserAccount userAccount, final boolean getChildren) throws SystemException {

    final String ouAttributeName =
        EscidocConfiguration.getInstance()
            .get(EscidocConfiguration.ESCIDOC_CORE_AA_OU_ATTRIBUTE_NAME);
    if (ouAttributeName == null || ouAttributeName.length() == 0) {
      return CustomEvaluationResultBuilder.createEmptyEvaluationResult();
    }
    final List<UserAttribute> attributes =
        userAccountDao.retrieveAttributes(userAccount, ouAttributeName);
    final EvaluationResult result;
    if (attributes == null || attributes.isEmpty()) {
      result = CustomEvaluationResultBuilder.createEmptyEvaluationResult();
    } else {
      final List<StringAttribute> results = new ArrayList<StringAttribute>();
      final Collection<String> ouIds = new ArrayList<String>();
      for (final UserAttribute attribute : attributes) {
        results.add(new StringAttribute(attribute.getValue()));
        if (getChildren) {
          ouIds.add(attribute.getValue());
        }
      }
      if (getChildren) {
        final List<String> childOus =
            tripleStoreUtility.getChildrenPath(ouIds, new ArrayList<String>());
        if (childOus != null) {
          for (final String childOu : childOus) {
            results.add(new StringAttribute(childOu));
          }
        }
      }

      result = new EvaluationResult(new BagAttribute(Constants.URI_XMLSCHEMA_STRING, results));
    }
    return result;
  }
  /**
   * 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};
  }