Esempio n. 1
0
 /**
  * Compare this object with the given one.
  *
  * <p>Will return true iff the other object is an Author and all fields are identical on a
  * string comparison.
  */
 @Override
 public boolean equals(Object o) {
   if (!(o instanceof Author)) {
     return false;
   }
   Author a = (Author) o;
   return EntryUtil.equals(firstPart, a.firstPart)
       && EntryUtil.equals(firstAbbr, a.firstAbbr)
       && EntryUtil.equals(vonPart, a.vonPart)
       && EntryUtil.equals(lastPart, a.lastPart)
       && EntryUtil.equals(jrPart, a.jrPart);
 }
Esempio n. 2
0
 public int getBackgroundColor() {
   switch (result) {
     case WIN:
       return EntryUtil.getWinnerColor();
     case LOSE:
       return EntryUtil.getDownColor();
     case STAY:
       return EntryUtil.getStayColor();
     default:
       return 0xFFFFFFFF;
   }
 }
Esempio n. 3
0
 public GroupEntry(
     String name,
     String country,
     String race,
     String place,
     int matchesWon,
     int matchesLost,
     int mapsWon,
     int mapsLost,
     String result) {
   this.name = name;
   this.country = EntryUtil.getCountryFromString(country);
   this.race = EntryUtil.getRaceFromString(race);
   this.place = place != null && place.length() > 0 ? Integer.parseInt(place) : -1;
   this.matchesWon = matchesWon;
   this.matchesLost = matchesLost;
   this.mapsWon = mapsWon;
   this.mapsLost = mapsLost;
   this.result = getResultFromString(result);
 }
Esempio n. 4
0
  public long updatePart(String userId, long partId, PartData part) {
    Entry existing = dao.get(partId);
    authorization.expectWrite(userId, existing);

    Entry entry = InfoToModelFactory.updateEntryField(part, existing);
    entry.getLinkedEntries().clear();
    if (part.getLinkedParts() != null && part.getLinkedParts().size() > 0) {
      for (PartData data : part.getLinkedParts()) {
        Entry linked = dao.getByPartNumber(data.getPartId());

        // check permissions on link
        if (!authorization.canRead(userId, linked)) {
          continue;
        }

        if (!canLink(entry, linked)) continue;

        entry.getLinkedEntries().add(linked);
      }
    }

    entry.setModificationTime(Calendar.getInstance().getTime());
    if (entry.getVisibility() == Visibility.DRAFT.getValue()) {
      List<EntryField> invalidFields = EntryUtil.validates(part);
      if (invalidFields.isEmpty()) entry.setVisibility(Visibility.OK.getValue());
    }
    entry = dao.update(entry);

    // check pi email
    String piEmail = entry.getPrincipalInvestigatorEmail();
    if (StringUtils.isNotEmpty(piEmail)) {
      Account pi = DAOFactory.getAccountDAO().getByEmail(piEmail);
      if (pi != null) {
        // add write permission for the PI (method also checks to see if permission already exists)
        AccessPermission accessPermission = new AccessPermission();
        accessPermission.setArticle(AccessPermission.Article.ACCOUNT);
        accessPermission.setArticleId(pi.getId());
        accessPermission.setType(AccessPermission.Type.WRITE_ENTRY);
        accessPermission.setTypeId(entry.getId());
        permissionsController.addPermission(userId, accessPermission);
      }
    }

    return entry.getId();
  }
Esempio n. 5
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);
  }