Search in sources :

Example 51 with Funding

use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.

the class MapperFacadeFactory method getFundingMapperFacade.

public MapperFacade getFundingMapperFacade() {
    MapperFactory mapperFactory = getNewMapperFactory();
    ConverterFactory converterFactory = mapperFactory.getConverterFactory();
    converterFactory.registerConverter("fundingExternalIdentifiersConverterId", new JSONFundingExternalIdentifiersConverterV2());
    converterFactory.registerConverter("fundingContributorsConverterId", new JsonOrikaConverter<FundingContributors>());
    ClassMapBuilder<Funding, ProfileFundingEntity> fundingClassMap = mapperFactory.classMap(Funding.class, ProfileFundingEntity.class);
    addV2CommonFields(fundingClassMap);
    registerSourceConverters(mapperFactory, fundingClassMap);
    fundingClassMap.field("type", "type");
    fundingClassMap.field("organizationDefinedType.content", "organizationDefinedType");
    fundingClassMap.field("title.title.content", "title");
    fundingClassMap.field("title.translatedTitle.content", "translatedTitle");
    fundingClassMap.field("title.translatedTitle.languageCode", "translatedTitleLanguageCode");
    fundingClassMap.field("description", "description");
    fundingClassMap.field("amount.content", "numericAmount");
    fundingClassMap.field("amount.currencyCode", "currencyCode");
    fundingClassMap.field("url.value", "url");
    fundingClassMap.fieldBToA("org.name", "organization.name");
    fundingClassMap.fieldBToA("org.city", "organization.address.city");
    fundingClassMap.fieldBToA("org.region", "organization.address.region");
    fundingClassMap.fieldBToA("org.country", "organization.address.country");
    fundingClassMap.fieldBToA("org.orgDisambiguated.sourceId", "organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier");
    fundingClassMap.fieldBToA("org.orgDisambiguated.sourceType", "organization.disambiguatedOrganization.disambiguationSource");
    fundingClassMap.fieldBToA("org.orgDisambiguated.id", "organization.disambiguatedOrganization.id");
    fundingClassMap.fieldMap("externalIdentifiers", "externalIdentifiersJson").converter("fundingExternalIdentifiersConverterId").add();
    fundingClassMap.fieldMap("contributors", "contributorsJson").converter("fundingContributorsConverterId").add();
    fundingClassMap.register();
    ClassMapBuilder<FundingSummary, ProfileFundingEntity> fundingSummaryClassMap = mapperFactory.classMap(FundingSummary.class, ProfileFundingEntity.class);
    addV2CommonFields(fundingSummaryClassMap);
    registerSourceConverters(mapperFactory, fundingSummaryClassMap);
    fundingSummaryClassMap.field("type", "type");
    fundingSummaryClassMap.field("title.title.content", "title");
    fundingSummaryClassMap.field("title.translatedTitle.content", "translatedTitle");
    fundingSummaryClassMap.field("title.translatedTitle.languageCode", "translatedTitleLanguageCode");
    fundingSummaryClassMap.fieldMap("externalIdentifiers", "externalIdentifiersJson").converter("fundingExternalIdentifiersConverterId").add();
    fundingSummaryClassMap.fieldBToA("org.name", "organization.name");
    fundingSummaryClassMap.fieldBToA("org.city", "organization.address.city");
    fundingSummaryClassMap.fieldBToA("org.region", "organization.address.region");
    fundingSummaryClassMap.fieldBToA("org.country", "organization.address.country");
    fundingSummaryClassMap.fieldBToA("org.orgDisambiguated.sourceId", "organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier");
    fundingSummaryClassMap.fieldBToA("org.orgDisambiguated.sourceType", "organization.disambiguatedOrganization.disambiguationSource");
    fundingSummaryClassMap.fieldBToA("org.orgDisambiguated.id", "organization.disambiguatedOrganization.id");
    fundingSummaryClassMap.register();
    mapFuzzyDateToStartDateEntityAndEndDateEntity(mapperFactory);
    return mapperFactory.getMapperFacade();
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) JSONFundingExternalIdentifiersConverterV2(org.orcid.core.adapter.jsonidentifier.converter.JSONFundingExternalIdentifiersConverterV2) FundingContributors(org.orcid.jaxb.model.record_v2.FundingContributors) FundingSummary(org.orcid.jaxb.model.record.summary_v2.FundingSummary) ConverterFactory(ma.glasnost.orika.converter.ConverterFactory) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity)

Example 52 with Funding

use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.

the class ProfileFundingManagerTest method testGetAll.

@Test
public void testGetAll() {
    String orcid = "0000-0000-0000-0003";
    List<Funding> elements = profileFundingManager.getFundingList(orcid);
    assertNotNull(elements);
    assertEquals(5, elements.size());
    boolean found1 = false, found2 = false, found3 = false, found4 = false, found5 = false;
    for (Funding element : elements) {
        if (10 == element.getPutCode()) {
            found1 = true;
        } else if (11 == element.getPutCode()) {
            found2 = true;
        } else if (12 == element.getPutCode()) {
            found3 = true;
        } else if (13 == element.getPutCode()) {
            found4 = true;
        } else if (14 == element.getPutCode()) {
            found5 = true;
        } else {
            fail("Invalid put code found: " + element.getPutCode());
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    assertTrue(found4);
    assertTrue(found5);
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 53 with Funding

use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.

the class ProfileFundingManagerTest method testAddMultipleModifiesIndexingStatus.

@Test
public void testAddMultipleModifiesIndexingStatus() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Funding f1 = getFunding("F1");
    f1 = profileFundingManager.createFunding(claimedOrcid, f1, true);
    Funding f2 = getFunding("F2");
    f2 = profileFundingManager.createFunding(claimedOrcid, f2, true);
    Funding f3 = getFunding("F3");
    f3 = profileFundingManager.createFunding(claimedOrcid, f3, true);
    ProfileFundingEntity entity1 = profileFundingDao.find(f1.getPutCode());
    ProfileFundingEntity entity2 = profileFundingDao.find(f2.getPutCode());
    ProfileFundingEntity entity3 = profileFundingDao.find(f3.getPutCode());
    assertNotNull(entity1.getDisplayIndex());
    assertNotNull(entity2.getDisplayIndex());
    assertNotNull(entity3.getDisplayIndex());
    assertEquals(Long.valueOf(0), entity3.getDisplayIndex());
    // Rollback all changes
    profileFundingDao.remove(entity1.getId());
    profileFundingDao.remove(entity2.getId());
    profileFundingDao.remove(entity3.getId());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Funding(org.orcid.jaxb.model.record_v2.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 54 with Funding

use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.

the class ProfileFundingManagerImpl method updateFunding.

/**
 * Updates a funding that belongs to the given user
 * @param orcid
 *          The user
 * @param funding
 *          The funding to update
 * @return the updated funding
 */
@Override
public Funding updateFunding(String orcid, Funding funding, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    ProfileFundingEntity pfe = profileFundingDao.getProfileFunding(orcid, funding.getPutCode());
    Visibility originalVisibility = pfe.getVisibility();
    // Save the original source
    String existingSourceId = pfe.getSourceId();
    String existingClientSourceId = pfe.getClientSourceId();
    activityValidator.validateFunding(funding, sourceEntity, false, isApiRequest, originalVisibility);
    if (!isApiRequest) {
        List<ProfileFundingEntity> existingFundings = profileFundingDao.getByUser(orcid, getLastModified(orcid));
        for (ProfileFundingEntity existingFunding : existingFundings) {
            Funding existing = jpaJaxbFundingAdapter.toFunding(existingFunding);
            if (!existing.getPutCode().equals(funding.getPutCode())) {
                activityValidator.checkFundingExternalIdentifiersForDuplicates(funding.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
            }
        }
    }
    orcidSecurityManager.checkSource(pfe);
    jpaJaxbFundingAdapter.toProfileFundingEntity(funding, pfe);
    pfe.setVisibility(originalVisibility);
    // Be sure it doesn't overwrite the source
    pfe.setSourceId(existingSourceId);
    pfe.setClientSourceId(existingClientSourceId);
    // Updates the give organization with the latest organization from database, or, create a new one
    OrgEntity updatedOrganization = orgManager.getOrgEntity(funding);
    pfe.setOrg(updatedOrganization);
    pfe = profileFundingDao.merge(pfe);
    profileFundingDao.flush();
    if (!isApiRequest) {
        notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(pfe));
    }
    return jpaJaxbFundingAdapter.toFunding(pfe);
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Visibility(org.orcid.jaxb.model.common_v2.Visibility) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 55 with Funding

use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.

the class ProfileFundingManagerImpl method createFunding.

/**
 * Add a new funding to the given user
 * @param orcid
 *          The user to add the funding
 * @param funding
 *          The funding to add
 * @return the added funding
 */
@Override
@Transactional
public Funding createFunding(String orcid, Funding funding, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    activityValidator.validateFunding(funding, sourceEntity, true, isApiRequest, null);
    // Check for duplicates
    List<ProfileFundingEntity> existingFundings = profileFundingDao.getByUser(orcid, getLastModified(orcid));
    List<Funding> fundings = jpaJaxbFundingAdapter.toFunding(existingFundings);
    if (fundings != null && isApiRequest) {
        for (Funding exstingFunding : fundings) {
            activityValidator.checkFundingExternalIdentifiersForDuplicates(funding.getExternalIdentifiers(), exstingFunding.getExternalIdentifiers(), exstingFunding.getSource(), sourceEntity);
        }
    }
    ProfileFundingEntity profileFundingEntity = jpaJaxbFundingAdapter.toProfileFundingEntity(funding);
    // Updates the give organization with the latest organization from database
    OrgEntity updatedOrganization = orgManager.getOrgEntity(funding);
    profileFundingEntity.setOrg(updatedOrganization);
    // Set the source
    if (sourceEntity.getSourceProfile() != null) {
        profileFundingEntity.setSourceId(sourceEntity.getSourceProfile().getId());
    }
    if (sourceEntity.getSourceClient() != null) {
        profileFundingEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
    }
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    profileFundingEntity.setProfile(profile);
    setIncomingWorkPrivacy(profileFundingEntity, profile);
    DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(profileFundingEntity, isApiRequest);
    profileFundingDao.persist(profileFundingEntity);
    profileFundingDao.flush();
    if (isApiRequest) {
        notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(profileFundingEntity));
    }
    return jpaJaxbFundingAdapter.toFunding(profileFundingEntity);
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Funding (org.orcid.jaxb.model.record_v2.Funding)82 Test (org.junit.Test)73 ClientResponse (com.sun.jersey.api.client.ClientResponse)28 ArrayList (java.util.ArrayList)16 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)16 Response (javax.ws.rs.core.Response)15 DBUnitTest (org.orcid.test.DBUnitTest)15 Url (org.orcid.jaxb.model.common_v2.Url)14 Title (org.orcid.jaxb.model.common_v2.Title)11 Work (org.orcid.jaxb.model.record_v2.Work)10 List (java.util.List)9 FundingTitle (org.orcid.jaxb.model.record_v2.FundingTitle)9 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)9 Funding (org.orcid.jaxb.model.record_rc1.Funding)8 IOException (java.io.IOException)7 InputStreamReader (java.io.InputStreamReader)6 Reader (java.io.Reader)6 BaseTest (org.orcid.core.BaseTest)6 Funding (org.orcid.jaxb.model.record_rc4.Funding)6 Education (org.orcid.jaxb.model.record_v2.Education)6