Beispiel #1
0
  /**
   * Retrieves and sets the default values for the entry. Some of these values (e.g. PI, and Funding
   * Source) are set by individual users as part of their personal preferences
   *
   * @param userId Unique identifier for user requesting the values.
   * @param type entry type
   * @return PartData object with the retrieve part defaults
   */
  public PartData getPartDefaults(String userId, EntryType type) {
    PartData partData = new PartData(type);
    PreferencesController preferencesController = new PreferencesController();

    // pi defaults
    String value =
        preferencesController.getPreferenceValue(
            userId, PreferenceKey.PRINCIPAL_INVESTIGATOR.name());
    if (value != null) {
      Account piAccount = accountController.getByEmail(value);
      if (piAccount == null) {
        partData.setPrincipalInvestigator(value);
      } else {
        partData.setPrincipalInvestigator(piAccount.getFullName());
        partData.setPrincipalInvestigatorEmail(piAccount.getEmail());
        partData.setPrincipalInvestigatorId(piAccount.getId());
      }
    }

    // funding source defaults
    value = preferencesController.getPreferenceValue(userId, PreferenceKey.FUNDING_SOURCE.name());
    if (value != null) {
      partData.setFundingSource(value);
    }

    // owner and creator details
    Account account = accountController.getByEmail(userId);
    if (account != null) {
      partData.setOwner(account.getFullName());
      partData.setOwnerEmail(account.getEmail());
      partData.setCreator(partData.getOwner());
      partData.setCreatorEmail(partData.getOwnerEmail());
    }

    // set the entry type defaults
    return EntryUtil.setPartDefaults(partData);
  }
Beispiel #2
0
  private static Entry setCommon(Entry entry, PartData info) {
    if (entry == null || info == null) return null;

    if (info.getName() != null) entry.setName(info.getName());

    if (info.getSelectionMarkers() != null) {
      Set<SelectionMarker> markers = getSelectionMarkers(info.getSelectionMarkers(), entry);
      entry.setSelectionMarkers(markers);
    }

    if (info.getReferences() != null) entry.setReferences(info.getReferences());

    if (StringUtils.isBlank(entry.getPartNumber())) entry.setPartNumber(info.getPartId());

    Date currentTime = new Date();
    if (entry.getCreationTime() == null) entry.setCreationTime(currentTime);

    entry.setModificationTime(currentTime);

    if (info.getOwnerEmail() != null) {
      entry.setOwnerEmail(info.getOwnerEmail());
    }

    if (info.getOwner() != null) entry.setOwner(info.getOwner());

    if (info.getCreatorEmail() != null) {
      entry.setCreatorEmail(info.getCreatorEmail());
    }

    if (info.getCreator() != null) entry.setCreator(info.getCreator());

    if (info.getStatus() == null) {
      if (StringUtils.isBlank(entry.getStatus())) entry.setStatus("");
    } else entry.setStatus(info.getStatus());

    if (info.getAlias() != null) entry.setAlias(info.getAlias());

    if (info.getBioSafetyLevel() == null) {
      if (entry.getBioSafetyLevel() == null) entry.setBioSafetyLevel(0);
    } else entry.setBioSafetyLevel(info.getBioSafetyLevel());

    if (info.getShortDescription() != null) entry.setShortDescription(info.getShortDescription());
    if (info.getLongDescription() != null) entry.setLongDescription(info.getLongDescription());
    if (info.getIntellectualProperty() != null)
      entry.setIntellectualProperty(info.getIntellectualProperty());

    Set<Link> links = getLinks(info.getLinks(), entry);
    entry.setLinks(links);

    Visibility visibility = info.getVisibility();
    if (visibility != null) entry.setVisibility(visibility.getValue());

    // checking for null instead of blank since it could be cleared
    if (info.getFundingSource() != null) entry.setFundingSource(info.getFundingSource());
    if (info.getPrincipalInvestigator() != null)
      entry.setPrincipalInvestigator(info.getPrincipalInvestigator());
    if (info.getPrincipalInvestigatorEmail() != null)
      entry.setPrincipalInvestigatorEmail(info.getPrincipalInvestigatorEmail());

    if (info.getKeywords() != null) entry.setKeywords(info.getKeywords());

    // parameters
    List<Parameter> parameters = getParameters(info.getCustomFields(), entry);
    entry.setParameters(parameters);
    return entry;
  }