Exemple #1
0
 /** @see com.ardais.bigr.library.web.column.SampleColumnImpl#getBodyText(SampleRowParams) */
 protected String getBodyText(SampleRowParams rp) throws IOException {
   StringBuffer result = new StringBuffer(64);
   result.append("<td>");
   Escaper.htmlEscape(getRawBodyText(rp), result);
   result.append("</td>");
   return result.toString();
 }
  private String getSampleInfo(HashMap sampleNumberToSample, SecurityInfo securityInfo) {
    Set problems = new HashSet();
    List encounteredAliases = new ArrayList();

    Iterator i = sampleNumberToSample.keySet().iterator();
    while (i.hasNext()) {
      String sampleNumber = (String) i.next();
      String sampleIdOrAlias = (String) sampleNumberToSample.get(sampleNumber);
      String sampleTypeCui = null;
      String sampleAlias = null;
      // if the value begins with the prefix for any of our sample ids (FR, PA, SX) then
      // assume it is a sample id.  Return an error if the sample doesn't exist.
      if (IltdsUtils.isSystemSampleId(sampleIdOrAlias)) {
        try {
          SampleAccessBean sample = new SampleAccessBean(new SampleKey(sampleIdOrAlias));
          sampleTypeCui = sample.getSampleTypeCid();
          sampleAlias = sample.getCustomerId();
        } catch (ObjectNotFoundException e) {
          StringBuffer error = new StringBuffer(100);
          error.append("Sample ");
          error.append(sampleIdOrAlias);
          error.append(" does not exist in the database.");
          problems.add(error.toString());
        } catch (Exception e) {
          ApiFunctions.throwAsRuntimeException(e);
        }
      }
      // if the value does not begin with the prefix for any of our sample ids (FR, PA, SX) then
      // assume it is a sample alias and handle the alias as follows:
      // - if the alias corresponds to multiple existing sample ids, return an error.
      // - if the alias corresponds to a single existing sample id, see if the account to which that
      //      sample belongs requires unique aliases.
      //      - if not, return an error since we cannot be positive the sample we found was the one
      //        intended.
      //      - if so
      //         - if the specified alias has already been encountered return an error since the
      //           same sample cannot be scanned into multiple locations in a box.
      //         - if the alias has not yet been encountered then get the information for that
      //           sample.
      // - if the alias corresponds to no existing sample return an error.
      else {
        // pass false to the findSampleIdsFromCustomerId call, to take into account any samples that
        // have been created via a box scan but have not yet been annotated.
        List existingSamples = IltdsUtils.findSamplesFromCustomerId(sampleIdOrAlias, false);
        // if multiple samples with the specified alias were found, return an error.
        if (existingSamples.size() > 1) {
          StringBuffer error = new StringBuffer(100);
          error.append("The alias \"");
          error.append(Escaper.htmlEscapeAndPreserveWhitespace(sampleIdOrAlias));
          error.append("\" corresponds to multiple existing samples.  Please scan the specific");
          error.append(" sample id you wish to use.");
          problems.add(error.toString());
        }
        // if a single sample was found, do some further checking
        else if (existingSamples.size() == 1) {
          String accountId = ((SampleData) existingSamples.get(0)).getArdaisAcctKey();
          AccountDto accountDto = IltdsUtils.getAccountById(accountId, false, false);
          boolean aliasMustBeUnique =
              FormLogic.DB_YES.equalsIgnoreCase(accountDto.getRequireUniqueSampleAliases());
          // if the account to which the sample belongs does not require unique sample aliases,
          // return an error since we cannot be sure the sample we found was the one intended.
          if (!aliasMustBeUnique) {
            StringBuffer error = new StringBuffer(100);
            error.append("The alias \"");
            error.append(Escaper.htmlEscapeAndPreserveWhitespace(sampleIdOrAlias));
            error.append("\" does not uniquely identify a sample.");
            error.append(" Please scan the specific sample id you wish to use.");
            problems.add(error.toString());
          }
          // if we've already encountered this alias, return an error (the same sample cannot
          // be scanned into multiple locations in a box)
          else if (encounteredAliases.contains(sampleIdOrAlias.toUpperCase())) {
            StringBuffer error = new StringBuffer(100);
            error.append("The alias \"");
            error.append(Escaper.htmlEscapeAndPreserveWhitespace(sampleIdOrAlias));
            error.append("\" appears more than once.");
            problems.add(error.toString());
            // still fill in the sample information so the resulting screen looks correct (otherwise
            // the first instance of this alias has information but the second does not)
            SampleData sample = (SampleData) existingSamples.get(0);
            sampleIdOrAlias = sample.getSampleId();
            sampleTypeCui = sample.getSampleTypeCui();
            sampleAlias = sample.getSampleAlias();
          }
          // otherwise store the encountered alias (in uppercase, so we can compare subsequent
          // aliases to this one without case accounting for any differences) and get the
          // information
          // for the sample
          else {
            encounteredAliases.add(sampleIdOrAlias.toUpperCase());
            SampleData sample = (SampleData) existingSamples.get(0);
            sampleIdOrAlias = sample.getSampleId();
            sampleTypeCui = sample.getSampleTypeCui();
            sampleAlias = sample.getSampleAlias();
          }
        }
        // if no matching sample was found, return an error
        else {
          StringBuffer error = new StringBuffer(100);
          error.append("Sample \"");
          error.append(Escaper.htmlEscapeAndPreserveWhitespace(sampleIdOrAlias));
          error.append("\" does not exist in the database.");
          problems.add(error.toString());
        }
      }
      // Create a sample data to hold the information
      SampleData sample = new SampleData();
      sample.setSampleId(sampleIdOrAlias);
      sample.setSampleAlias(sampleAlias);
      sample.setSampleTypeCui(sampleTypeCui);
      if (!ApiFunctions.isEmpty(sampleTypeCui)) {
        sample.setSampleType(GbossFactory.getInstance().getDescription(sampleTypeCui));
      }
      // replace the map entry with the sample data object
      sampleNumberToSample.put(sampleNumber, sample);
    }

    String returnValue = null;
    if (!problems.isEmpty()) {
      StringBuffer buff = new StringBuffer("The following problems were found: ");
      Iterator problemIterator = problems.iterator();
      while (problemIterator.hasNext()) {
        buff.append((String) problemIterator.next());
        buff.append("  ");
      }
      returnValue = buff.toString();
    }
    return returnValue;
  }
  /** @see com.ardais.bigr.iltds.btx.BTXDetails#doGetDetailsAsHTML() */
  protected String doGetDetailsAsHTML() {
    // NOTE: This method must not make use of any fields that aren't
    // set by the populateFromHistoryRecord method.
    //
    // For this object type, the fields we can use here are:
    // setObjectType
    // one of the following, depending upon object type
    //   getUserData().setUserId
    //   getAccountData.setId
    // setAddedPrivileges
    // setRemovedPrivileges
    // setAssignedPrivileges - note this will be null
    // setAllPrivileges - note this will be null
    // setSelectedPrivileges - note this will be null
    // setRoleBasedPrivileges - note this will be null

    // The result has this form:
    //    User <userId> had access to the following privilege revoked: <privilege names>.
    //    They were granted access to the following privileges: <privilege names>.
    StringBuffer sb = new StringBuffer(512);
    if (Constants.OBJECT_TYPE_ACCOUNT.equalsIgnoreCase(getObjectType())) {
      sb.append("Account ");
      Escaper.htmlEscape(getAccountData().getId(), sb);
    } else if (Constants.OBJECT_TYPE_USER.equalsIgnoreCase(getObjectType())) {
      sb.append("User ");
      Escaper.htmlEscape(getUserData().getUserId(), sb);
    }
    // if no changes were made, say that
    if (getRemovedPrivileges().size() == 0 && getAddedPrivileges().size() == 0) {
      sb.append(" had no changes made to");
      if (Constants.OBJECT_TYPE_ACCOUNT.equalsIgnoreCase(getObjectType())) {
        sb.append(" its");
      } else if (Constants.OBJECT_TYPE_USER.equalsIgnoreCase(getObjectType())) {
        sb.append(" their");
      }
      sb.append(" privilege access.");
    } else {
      if (getRemovedPrivileges().size() > 0) {
        sb.append(" had access to the following privileges revoked: ");
        Iterator iterator = getRemovedPrivileges().iterator();
        boolean addComma = false;
        while (iterator.hasNext()) {
          if (addComma) {
            sb.append(", ");
          }
          addComma = true;
          sb.append(((PrivilegeDto) iterator.next()).getDescription());
        }
        sb.append(".");
      }
      if (getAddedPrivileges().size() > 0) {
        // if we said something about removed privileges, start a new sentence.
        if (getRemovedPrivileges().size() > 0) {
          if (Constants.OBJECT_TYPE_ACCOUNT.equalsIgnoreCase(getObjectType())) {
            sb.append(" It was");
          } else if (Constants.OBJECT_TYPE_USER.equalsIgnoreCase(getObjectType())) {
            sb.append(" They were ");
          }
        } else {
          sb.append(" was ");
        }
        sb.append("granted access to the following privileges: ");
        Iterator iterator = getAddedPrivileges().iterator();
        boolean addComma = false;
        while (iterator.hasNext()) {
          if (addComma) {
            sb.append(", ");
          }
          addComma = true;
          sb.append(((PrivilegeDto) iterator.next()).getDescription());
        }
        sb.append(".");
      }
    }
    return sb.toString();
  }