コード例 #1
0
  private void check(
      JAXBResource jaxbResource, UserDetails user, StringApiResponse response, boolean add)
      throws Throwable {
    ResourceInterface resourcePrototype =
        this.getResourceManager().createResourceType(jaxbResource.getTypeCode());
    if (null == resourcePrototype) {
      this.addValidationError(
          "Invalid resource type - '" + jaxbResource.getTypeCode() + "'", response);
    }
    if (null == user) {
      user = this.getUserManager().getGuestUser();
    }
    String groupName = jaxbResource.getMainGroup();
    if (null == groupName || groupName.trim().length() == 0) {
      this.addValidationError("Group required", response);
    } else {
      if (null == this.getGroupManager().getGroup(groupName)) {
        // this.addValidationError("Group '" + groupName + "' does not exist", response);
      } else if (!this.getAuthorizationManager().isAuthOnGroup(user, groupName)) {
        // this.addValidationError("Group '" + groupName + "' not allowed", response);
      }
    }
    if (add) {
      if (null == jaxbResource.getBase64()) {
        this.addValidationError("Binary Image required", response);
      }
      if (null == jaxbResource.getFileName() || jaxbResource.getFileName().trim().length() == 0) {
        this.addValidationError("FileName required", response);
      }
    } else {
      ResourceInterface oldResource = this.getResourceManager().loadResource(jaxbResource.getId());
      if (null == oldResource) {
        this.addValidationError(
            "Resource with id '" + jaxbResource.getId() + "' does not exist", response);
      } else if (!oldResource.getMainGroup().equals(jaxbResource.getMainGroup())) {
        this.addValidationError(
            "Resource group has to be '" + oldResource.getMainGroup() + "'", response);
      }
    }
    if (this.isDuplicateFile(jaxbResource, resourcePrototype, add)) {
      this.addValidationError(
          "File '" + jaxbResource.getFileName() + "' is already present on Archive", response);
    }
    if (null == jaxbResource.getDescription()
        || jaxbResource.getDescription().trim().length() == 0) {
      this.addValidationError("Description required", response);
    }

    if (null == jaxbResource.getTypeCode() || jaxbResource.getTypeCode().trim().length() == 0) {
      this.addValidationError("TypeCode required", response);
    }
  }
コード例 #2
0
 private boolean isDuplicateFile(
     JAXBResource jaxbResource, ResourceInterface resourcePrototype, boolean add) {
   if (null == jaxbResource.getBase64()) return false;
   boolean addError = true;
   String formFileName = jaxbResource.getFileName();
   try {
     resourcePrototype.setMainGroup(jaxbResource.getMainGroup());
     if (resourcePrototype.exists(formFileName)) {
       if (!add) {
         ResourceInterface masterResource =
             this.getResourceManager().loadResource(jaxbResource.getId());
         String masterFileName =
             (null != masterResource) ? masterResource.getMasterFileName() : null;
         if (null != masterFileName && masterFileName.equalsIgnoreCase(formFileName)) {
           addError = false;
         }
       }
     } else {
       addError = false;
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(
         t,
         this,
         "isDuplicateFile",
         "Error while check duplicate file - master file name '" + formFileName + "'");
   }
   return addError;
 }