Search in sources :

Example 1 with IdentifierTypeEntity

use of org.orcid.persistence.jpa.entities.IdentifierTypeEntity in project ORCID-Source by ORCID.

the class IdentifierTypePOJOConverter method fromPojo.

public IdentifierTypeEntity fromPojo(IdentifierType id) {
    IdentifierTypeEntity entity = new IdentifierTypeEntity();
    entity.setId(id.getPutCode());
    entity.setName(externalIdentifierTypeConverter.convertTo(id.getName(), null));
    entity.setIsDeprecated(id.getDeprecated());
    entity.setResolutionPrefix(id.getResolutionPrefix());
    entity.setValidationRegex(id.getValidationRegex());
    entity.setDateCreated(id.getDateCreated());
    entity.setLastModified(id.getLastModified());
    entity.setSourceClient(id.getSourceClient());
    entity.setPrimaryUse(id.getPrimaryUse());
    entity.setIsCaseSensitive(id.getCaseSensitive());
    return entity;
}
Also used : IdentifierTypeEntity(org.orcid.persistence.jpa.entities.IdentifierTypeEntity)

Example 2 with IdentifierTypeEntity

use of org.orcid.persistence.jpa.entities.IdentifierTypeEntity in project ORCID-Source by ORCID.

the class IdentifierTypeManagerImpl method fetchIdentifierTypeByDatabaseName.

/**
     * Null locale will result in Locale.ENGLISH
     */
@Override
@Cacheable("identifier-types")
public IdentifierType fetchIdentifierTypeByDatabaseName(String name, Locale loc) {
    loc = (loc == null) ? Locale.ENGLISH : loc;
    IdentifierTypeEntity entity = idTypeDao.getEntityByName(name);
    IdentifierType type = adapter.fromEntity(entity);
    type.setDescription(getMessage(type.getName(), loc));
    return type;
}
Also used : IdentifierTypeEntity(org.orcid.persistence.jpa.entities.IdentifierTypeEntity) IdentifierType(org.orcid.pojo.IdentifierType) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 3 with IdentifierTypeEntity

use of org.orcid.persistence.jpa.entities.IdentifierTypeEntity in project ORCID-Source by ORCID.

the class IdentifierTypeManagerImpl method fetchIdentifierTypesByAPITypeName.

/**
     * Returns an immutable map of API Type Name->identifierType objects.
     * Null locale will result in Locale.ENGLISH
     * 
     */
@Override
@Cacheable("identifier-types-map")
public Map<String, IdentifierType> fetchIdentifierTypesByAPITypeName(Locale loc) {
    loc = (loc == null) ? Locale.ENGLISH : loc;
    List<IdentifierTypeEntity> entities = idTypeDao.getEntities();
    Map<String, IdentifierType> ids = new HashMap<String, IdentifierType>();
    for (IdentifierTypeEntity e : entities) {
        IdentifierType id = adapter.fromEntity(e);
        id.setDescription(getMessage(id.getName(), loc));
        ids.put(id.getName(), id);
    }
    return Collections.unmodifiableMap(ids);
}
Also used : HashMap(java.util.HashMap) IdentifierTypeEntity(org.orcid.persistence.jpa.entities.IdentifierTypeEntity) IdentifierType(org.orcid.pojo.IdentifierType) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 4 with IdentifierTypeEntity

use of org.orcid.persistence.jpa.entities.IdentifierTypeEntity in project ORCID-Source by ORCID.

the class IdentifierTypeManagerImpl method updateIdentifierType.

@Override
@CacheEvict(value = { "identifier-types", "identifier-types-map" }, allEntries = true)
public IdentifierType updateIdentifierType(IdentifierType id) {
    IdentifierTypeEntity entity = idTypeDao.getEntityByName(externalIdentifierTypeConverter.convertTo(id.getName(), null));
    SourceEntity sourceEntity = new SourceEntity();
    sourceEntity.setSourceClient(entity.getSourceClient());
    securityManager.checkSource(entity);
    entity.setIsDeprecated(id.getDeprecated());
    entity.setResolutionPrefix(id.getResolutionPrefix());
    entity.setValidationRegex(id.getValidationRegex());
    entity.setLastModified(new Date());
    entity.setIsCaseSensitive(id.getCaseSensitive());
    entity.setPrimaryUse(id.getPrimaryUse());
    entity = idTypeDao.updateIdentifierType(entity);
    return adapter.fromEntity(entity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) IdentifierTypeEntity(org.orcid.persistence.jpa.entities.IdentifierTypeEntity) Date(java.util.Date) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 5 with IdentifierTypeEntity

use of org.orcid.persistence.jpa.entities.IdentifierTypeEntity in project ORCID-Source by ORCID.

the class IdentifierTypeDaoTest method test1AddUpdateFetchID.

@Test
public void test1AddUpdateFetchID() {
    IdentifierTypeEntity e1 = new IdentifierTypeEntity();
    e1.setName("TEST_A");
    e1.setResolutionPrefix("http://whatever.com/{id}");
    e1.setValidationRegex("blah");
    e1.setSourceClient(clientDetailsDao.findByClientId("APP-6666666666666666", new Date().getTime()));
    e1.setIsCaseSensitive(true);
    e1.setPrimaryUse("pu");
    IdentifierTypeEntity e2 = idTypeDao.addIdentifierType(e1);
    assertNotNull(e2.getId());
    e1 = idTypeDao.getEntityByName("TEST_A");
    assertEquals("TEST_A", e1.getName());
    assertEquals("http://whatever.com/{id}", e1.getResolutionPrefix());
    assertEquals("blah", e1.getValidationRegex());
    assertFalse(e1.getIsDeprecated());
    assertNotNull(e1.getId());
    assertEquals("APP-6666666666666666", e1.getSourceClient().getClientId());
    assertTrue((new Date()).after(e1.getDateCreated()));
    assertTrue((new Date()).after(e1.getLastModified()));
    assertEquals("APP-6666666666666666", e1.getSourceClient().getId());
    assertTrue(e1.getIsCaseSensitive());
    assertEquals("pu", e1.getPrimaryUse());
    //update
    //e1 = idTypeDao.getEntityByName("TEST_A");
    Date last = e1.getLastModified();
    e1.setResolutionPrefix("http://whatever2.com/{id}");
    e1.setValidationRegex("blah2");
    e1.setIsDeprecated(true);
    e1 = idTypeDao.updateIdentifierType(e1);
    assertEquals("TEST_A", e1.getName());
    assertEquals("http://whatever2.com/{id}", e1.getResolutionPrefix());
    assertEquals("blah2", e1.getValidationRegex());
    assertTrue(e1.getIsDeprecated());
    assertNotNull(e1.getId());
    assertEquals("APP-6666666666666666", e1.getSourceClient().getClientId());
    assertTrue((new Date()).after(e1.getDateCreated()));
    assertTrue(last.before(e1.getLastModified()));
    e1 = idTypeDao.getEntityByName("TEST_A");
    e1 = idTypeDao.getEntityByName("TEST_A");
}
Also used : IdentifierTypeEntity(org.orcid.persistence.jpa.entities.IdentifierTypeEntity) Date(java.util.Date) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Aggregations

IdentifierTypeEntity (org.orcid.persistence.jpa.entities.IdentifierTypeEntity)10 Date (java.util.Date)5 Test (org.junit.Test)4 IdentifierType (org.orcid.pojo.IdentifierType)4 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 BaseTest (org.orcid.core.BaseTest)2 IdentifierTypePOJOConverter (org.orcid.core.adapter.impl.IdentifierTypePOJOConverter)2 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)2 DBUnitTest (org.orcid.test.DBUnitTest)2 CacheEvict (org.springframework.cache.annotation.CacheEvict)2 Cacheable (org.springframework.cache.annotation.Cacheable)2 HashMap (java.util.HashMap)1 Transactional (org.springframework.transaction.annotation.Transactional)1