Exemplo n.º 1
0
 @Override
 public Contributor[] getMaintainers() {
   final Contributor contributor1 = new Contributor("Nathaniel Oco");
   contributor1.setUrl("http://www.dlsu.edu.ph/research/centers/adric/nlp/");
   final Contributor contributor2 = new Contributor("Allan Borra");
   contributor2.setUrl("http://www.dlsu.edu.ph/research/centers/adric/nlp/faculty/borra.asp");
   return new Contributor[] {contributor1, contributor2};
 }
Exemplo n.º 2
0
  /**
   * Updates local contribution and commands. Called before information exchange attempts. Uses
   * local address of contributor (if it is not null), this is replaced on the other side of the
   * communication channel by the correct global address.
   */
  private synchronized void updateLocalInfo() {

    if (contributor != null) {
      myContribution =
          new ContributionBox(new Address(contributor.getName()), contributor.getContribution());
    }

    final Long now = new Long(System.currentTimeMillis());
    if (controller != null) {
      Set newcomms = controller.getCommands();
      if (newcomms == null) return;
      Iterator i = newcomms.iterator();
      while (i.hasNext()) commands.put(i.next(), now);
    }
  }
Exemplo n.º 3
0
  /**
   * Handles a message. Knows type "collectiveUpdate-"+name only. It is the responsibility of the
   * owner to propagate messages of this type using this method.
   */
  public boolean handleMessage(Message m, Object o) {

    if (!shouldLive || !m.getType().equals("collectiveUpdate-" + name)) return false;

    final String logSender = observer + "#collectiveUpdate";

    Logger.debug(logSender, "Update from " + m.getSender());

    /**/
    if (!m.getRecipient().name.equals(contributor.getName()))
      Logger.warning(
          logSender,
          "Recipient and my contributor are not the same:\n"
              + "Recipient: "
              + m.getRecipient().name
              + "\n"
              + "Contributor: "
              + contributor.getName(),
          null);
    /**/

    Collective c = (Collective) o;

    // --- reset array representations
    cacheCollection = null;
    commandCollection = null;

    // --- remove possible garbage
    cache.remove(m.getRecipient().name);
    c.cache.remove(m.getRecipient().name);
    cache.remove(m.getSender().name);
    c.cache.remove(m.getSender().name);

    // --- sending our contributions
    if (contributor == null)
      Logger.warning(logSender, "Non-contributor observer is known by " + m.getSender(), null);
    updateLocalInfo();
    m.setReply(this);

    // --- update containers
    repairSenderAddress(c, m.getSender());
    merge(c);
    observer.collectiveUpdated((ContributionBox) cache.get(m.getSender().name));

    return true;
  }
Exemplo n.º 4
0
  /**
   * Construct a Collective object.
   *
   * @param c The contributions, the commands and the name will be initialized from this object.
   * @param o The observer that reads information from the collective. It must be non-null.
   * @param cb The contributor that contributes to the collective effort.
   * @param c The controller that issues collective-wide commands.
   */
  public Collective(Collective c, Observer o, Contributor cb, Controller cr) {

    this(c.name, o, cb, cr);

    if (c == null) throw new IllegalArgumentException("null collective");

    if (c.cache != null) cache.putAll(c.cache);
    if (c.commands != null) commands.putAll(c.commands);
    if (contributor != null) cache.remove(contributor.getName());
  }
Exemplo n.º 5
0
  /**
   * Returns a string describing the project.
   *
   * @return a string describing the project.
   */
  public String toString() {

    String result = getName() + " version " + getVersion() + ".\n";
    result = result + getCopyright() + ".\n";
    result = result + "\n";
    result = result + "For terms of use, see the licence below.\n";
    result = result + "\n";
    result = result + "FURTHER INFORMATION:";
    result = result + getInfo();
    result = result + "\n";
    result = result + "CONTRIBUTORS:";
    List contributors = getContributors();
    if (contributors != null) {
      Iterator iterator = getContributors().iterator();
      while (iterator.hasNext()) {
        Contributor contributor = (Contributor) iterator.next();
        result = result + contributor.getName() + " (" + contributor.getEmail() + ").";
      }
    } else {
      result = result + "None";
    }

    result = result + "\n";
    result = result + "OTHER LIBRARIES USED BY " + getName() + ":";
    List libraries = getLibraries();
    if (libraries != null) {
      Iterator iterator = getLibraries().iterator();
      while (iterator.hasNext()) {
        Library lib = (Library) iterator.next();
        result = result + lib.getName() + " " + lib.getVersion() + " (" + lib.getInfo() + ").";
      }
    } else {
      result = result + "None";
    }
    result = result + "\n";
    result = result + getName() + " LICENCE TERMS:";
    result = result + "\n";
    result = result + getLicenceText();

    return result;
  }
Exemplo n.º 6
0
 @Override
 public Contributor[] getMaintainers() {
   final Contributor contributor = new Contributor("Zdenko Podobný");
   contributor.setUrl("http://sk-spell.sk.cx");
   return new Contributor[] {contributor};
 }
Exemplo n.º 7
0
  /**
   * Initiates an information exchange with a known and living other base if such a base exists.
   *
   * @return true if refresh was succesful, false otherwise.
   */
  private boolean refresh() {

    final String logSender = observer + "#refresh";
    final String contrName = ((contributor != null) ? contributor.getName() : null);

    // --- refreshing local contribution and commands
    updateLocalInfo();

    // --- creating a random permutation of peers
    Vector peers = null;
    synchronized (cache) {
      peers = new Vector(cache.values());
      // just to be sure, shouldn't be there anyway
      if (contrName != null) peers.remove(cache.get(contrName));
    }
    Collections.shuffle(peers);
    if (peers.isEmpty()) {
      Logger.debug(logSender, "no peers in cache");
      return false;
    }

    // --- reset array representations
    cacheCollection = null;
    commandCollection = null;

    // --- trying to talk to random peer
    IRequest answer = null;
    Address peer = null;
    for (int i = 0; i < peers.size(); ++i) {
      if (!shouldLive) return false;

      peer = ((ContributionBox) peers.get(i)).contributor;
      Logger.debug(logSender, "asking " + peer);

      answer = observer.fireMessage(peer, "collectiveUpdate-" + name, this);
      while (answer.getStatus() == IRequest.WAITING) {
        try {
          Thread.sleep(100);
        } catch (Exception e) {
        }
      }
      if (answer.getStatus() == IRequest.DONE) break;
      Logger.debug(logSender, "not accessable: " + peer);
    }

    if (answer.getStatus() != IRequest.DONE) {
      Logger.debug(logSender, "no accessable peers");
      observer.collectiveUpdated(null);
      return false;
    } else {
      Collective c = (Collective) answer.getInfo("reply");

      // --- remove possible garbage
      if (contributor != null) {
        cache.remove(contributor.getName());
        c.cache.remove(contributor.getName());
      }
      cache.remove(peer.name);
      c.cache.remove(peer.name);

      repairSenderAddress(c, peer);
      merge(c);
      observer.collectiveUpdated((ContributionBox) cache.get(c.myContribution.contributor.name));
      return true;
    }
  }
Exemplo n.º 8
0
  @Deprecated
  public static FundingForm valueOf(org.orcid.jaxb.model.message.Funding funding) {
    FundingForm result = new FundingForm();

    result.setDateSortString(
        PojoUtil.createDateSortString(funding.getStartDate(), funding.getEndDate()));

    if (funding.getPutCode() != null) result.setPutCode(Text.valueOf(funding.getPutCode()));

    if (funding.getAmount() != null) {
      if (StringUtils.isNotEmpty(funding.getAmount().getContent())) {
        String cleanNumber = funding.getAmount().getContent().trim();
        result.setAmount(Text.valueOf(cleanNumber));
      }
      if (funding.getAmount().getCurrencyCode() != null)
        result.setCurrencyCode(Text.valueOf(funding.getAmount().getCurrencyCode()));
      else result.setCurrencyCode(new Text());
    } else {
      result.setAmount(new Text());
      result.setCurrencyCode(new Text());
    }
    if (StringUtils.isNotEmpty(funding.getDescription()))
      result.setDescription(Text.valueOf(funding.getDescription()));
    else result.setDescription(new Text());

    if (funding.getStartDate() != null) result.setStartDate(Date.valueOf(funding.getStartDate()));

    if (funding.getEndDate() != null) result.setEndDate(Date.valueOf(funding.getEndDate()));

    if (funding.getType() != null) result.setFundingType(Text.valueOf(funding.getType().value()));
    else result.setFundingType(new Text());

    if (funding.getOrganizationDefinedFundingType() != null) {
      OrgDefinedFundingSubType OrgDefinedFundingSubType = new OrgDefinedFundingSubType();
      OrgDefinedFundingSubType.setSubtype(
          Text.valueOf(funding.getOrganizationDefinedFundingType().getContent()));
      OrgDefinedFundingSubType.setAlreadyIndexed(false);
      result.setOrganizationDefinedFundingSubType(OrgDefinedFundingSubType);
    }

    org.orcid.jaxb.model.message.Source source = funding.getSource();
    if (source != null) {
      result.setSource(source.retrieveSourcePath());
      if (source.getSourceName() != null) {
        result.setSourceName(source.getSourceName().getContent());
      }
    }

    if (funding.getTitle() != null) {
      FundingTitleForm fundingTitle = new FundingTitleForm();
      if (funding.getTitle().getTitle() != null)
        fundingTitle.setTitle(Text.valueOf(funding.getTitle().getTitle().getContent()));
      else fundingTitle.setTitle(new Text());
      if (funding.getTitle().getTranslatedTitle() != null) {
        TranslatedTitleForm translatedTitle = new TranslatedTitleForm();
        translatedTitle.setContent(funding.getTitle().getTranslatedTitle().getContent());
        translatedTitle.setLanguageCode(funding.getTitle().getTranslatedTitle().getLanguageCode());
        fundingTitle.setTranslatedTitle(translatedTitle);
      }
      result.setFundingTitle(fundingTitle);
    } else {
      FundingTitleForm fundingTitle = new FundingTitleForm();
      fundingTitle.setTitle(new Text());
      result.setFundingTitle(fundingTitle);
    }

    if (funding.getUrl() != null) result.setUrl(Text.valueOf(funding.getUrl().getValue()));
    else result.setUrl(new Text());

    if (funding.getVisibility() != null)
      result.setVisibility(Visibility.valueOf(funding.getVisibility()));

    // Set the disambiguated organization
    org.orcid.jaxb.model.message.Organization organization = funding.getOrganization();
    result.setFundingName(Text.valueOf(organization.getName()));
    org.orcid.jaxb.model.message.DisambiguatedOrganization disambiguatedOrganization =
        organization.getDisambiguatedOrganization();
    if (disambiguatedOrganization != null) {
      if (StringUtils.isNotEmpty(
          disambiguatedOrganization.getDisambiguatedOrganizationIdentifier())) {
        result.setDisambiguatedFundingSourceId(
            Text.valueOf(disambiguatedOrganization.getDisambiguatedOrganizationIdentifier()));
        result.setDisambiguationSource(
            Text.valueOf(disambiguatedOrganization.getDisambiguationSource()));
      }
    }
    org.orcid.jaxb.model.message.OrganizationAddress organizationAddress =
        organization.getAddress();
    if (organizationAddress != null) {
      if (!PojoUtil.isEmpty(organizationAddress.getCity()))
        result.setCity(Text.valueOf(organizationAddress.getCity()));
      else result.setCity(new Text());
      if (!PojoUtil.isEmpty(organizationAddress.getRegion()))
        result.setRegion(Text.valueOf(organizationAddress.getRegion()));
      else result.setRegion(new Text());
      if (organizationAddress.getCountry() != null)
        result.setCountry(Text.valueOf(organizationAddress.getCountry().value()));
      else result.setCountry(new Text());

    } else {
      result.setCountry(new Text());
      result.setCity(new Text());
      result.setRegion(new Text());
    }

    // Set contributors
    if (funding.getFundingContributors() != null) {
      List<Contributor> contributors = new ArrayList<Contributor>();
      for (org.orcid.jaxb.model.message.FundingContributor fContributor :
          funding.getFundingContributors().getContributor()) {
        Contributor contributor = Contributor.valueOf(fContributor);
        contributors.add(contributor);
      }
      result.setContributors(contributors);
    }

    List<FundingExternalIdentifierForm> externalIdentifiersList =
        new ArrayList<FundingExternalIdentifierForm>();
    // Set external identifiers
    if (funding.getFundingExternalIdentifiers() != null) {
      for (org.orcid.jaxb.model.message.FundingExternalIdentifier fExternalIdentifier :
          funding.getFundingExternalIdentifiers().getFundingExternalIdentifier()) {
        FundingExternalIdentifierForm fundingExternalIdentifierForm =
            FundingExternalIdentifierForm.valueOf(fExternalIdentifier);
        externalIdentifiersList.add(fundingExternalIdentifierForm);
      }
    }
    result.setExternalIdentifiers(externalIdentifiersList);

    result.setCreatedDate(Date.valueOf(funding.getCreatedDate()));
    result.setLastModified(Date.valueOf(funding.getLastModifiedDate()));

    return result;
  }
Exemplo n.º 9
0
  public Funding toFunding() {
    Funding result = new Funding();
    Amount orcidAmount = new Amount();
    if (!PojoUtil.isEmpty(amount)) orcidAmount.setContent(amount.getValue());
    if (!PojoUtil.isEmpty(currencyCode)) orcidAmount.setCurrencyCode(currencyCode.getValue());
    result.setAmount(orcidAmount);
    if (!PojoUtil.isEmpty(description)) result.setDescription(description.getValue());
    if (!PojoUtil.isEmpty(startDate)) result.setStartDate(new FuzzyDate(startDate.toFuzzyDate()));
    if (!PojoUtil.isEmpty(endDate)) result.setEndDate(new FuzzyDate(endDate.toFuzzyDate()));
    if (!PojoUtil.isEmpty(putCode)) result.setPutCode(Long.valueOf(putCode.getValue()));
    if (fundingTitle != null) {
      result.setTitle(fundingTitle.toFundingTitle());
    }
    if (!PojoUtil.isEmpty(fundingType))
      result.setType(FundingType.fromValue(fundingType.getValue()));

    if (organizationDefinedFundingSubType != null
        && !PojoUtil.isEmpty(organizationDefinedFundingSubType.getSubtype()))
      result.setOrganizationDefinedType(
          new OrganizationDefinedFundingSubType(
              organizationDefinedFundingSubType.getSubtype().getValue()));

    if (!PojoUtil.isEmpty(url)) result.setUrl(new Url(url.getValue()));
    else result.setUrl(new Url(""));
    if (visibility != null)
      result.setVisibility(
          org.orcid.jaxb.model.common_rc2.Visibility.fromValue(visibility.getVisibility().value()));

    // Set Organization
    Organization organization = new Organization();
    if (!PojoUtil.isEmpty(fundingName)) organization.setName(fundingName.getValue());
    OrganizationAddress organizationAddress = new OrganizationAddress();
    organization.setAddress(organizationAddress);
    if (!PojoUtil.isEmpty(city)) organizationAddress.setCity(city.getValue());
    if (!PojoUtil.isEmpty(region)) {
      organizationAddress.setRegion(region.getValue());
    }
    if (!PojoUtil.isEmpty(country)) {
      organizationAddress.setCountry(Iso3166Country.fromValue(country.getValue()));
    }
    if (!PojoUtil.isEmpty(disambiguatedFundingSourceId)) {
      organization.setDisambiguatedOrganization(new DisambiguatedOrganization());
      organization
          .getDisambiguatedOrganization()
          .setDisambiguatedOrganizationIdentifier(disambiguatedFundingSourceId.getValue());
      organization
          .getDisambiguatedOrganization()
          .setDisambiguationSource(disambiguationSource.getValue());
    }
    result.setOrganization(organization);

    // Set contributors
    if (contributors != null && !contributors.isEmpty()) {
      FundingContributors fContributors = new FundingContributors();
      for (Contributor contributor : contributors) {
        if (!PojoUtil.isEmtpy(contributor))
          fContributors.getContributor().add(contributor.toFundingContributor());
      }
      result.setContributors(fContributors);
    }
    // Set external identifiers
    if (externalIdentifiers != null && !externalIdentifiers.isEmpty()) {
      FundingExternalIdentifiers fExternalIdentifiers = new FundingExternalIdentifiers();
      for (FundingExternalIdentifierForm fExternalIdentifier : externalIdentifiers) {
        if (!PojoUtil.isEmtpy(fExternalIdentifier))
          fExternalIdentifiers
              .getExternalIdentifier()
              .add(fExternalIdentifier.toFundingExternalIdentifier());
      }
      result.setExternalIdentifiers(fExternalIdentifiers);
    }

    return result;
  }