Search in sources :

Example 6 with IdentifierType

use of org.orcid.pojo.IdentifierType in project ORCID-Source by ORCID.

the class WorksController method workWorkExternalIdentifiersValidate.

@RequestMapping(value = "/work/workExternalIdentifiersValidate.json", method = RequestMethod.POST)
@ResponseBody
public WorkForm workWorkExternalIdentifiersValidate(@RequestBody WorkForm work) {
    for (WorkExternalIdentifier wId : work.getWorkExternalIdentifiers()) {
        if (wId.getWorkExternalIdentifierId() == null)
            wId.setWorkExternalIdentifierId(new Text());
        if (wId.getWorkExternalIdentifierType() == null)
            wId.setWorkExternalIdentifierType(new Text());
        wId.getWorkExternalIdentifierId().setErrors(new ArrayList<String>());
        wId.getWorkExternalIdentifierType().setErrors(new ArrayList<String>());
        // if has id type must be specified
        if (wId.getWorkExternalIdentifierId().getValue() != null && !wId.getWorkExternalIdentifierId().getValue().trim().equals("") && (wId.getWorkExternalIdentifierType().getValue() == null || wId.getWorkExternalIdentifierType().getValue().equals(""))) {
            setError(wId.getWorkExternalIdentifierType(), "NotBlank.currentWorkExternalIds.idType");
        } else if (wId.getWorkExternalIdentifierId().getValue() != null && wId.getWorkExternalIdentifierId().getValue().length() > 2084) {
            setError(wId.getWorkExternalIdentifierId(), "manualWork.length_less_2084");
        }
        // if type is set a id must set
        if (wId.getWorkExternalIdentifierType().getValue() != null && !wId.getWorkExternalIdentifierType().getValue().trim().equals("") && (wId.getWorkExternalIdentifierId().getValue() == null || wId.getWorkExternalIdentifierId().getValue().trim().equals(""))) {
            setError(wId.getWorkExternalIdentifierId(), "NotBlank.currentWorkExternalIds.id");
        }
        Map<String, IdentifierType> types = identifierTypeManager.fetchIdentifierTypesByAPITypeName(getLocale());
        if (wId.getWorkExternalIdentifierType().getValue() != null && !wId.getWorkExternalIdentifierType().getValue().trim().isEmpty() && !types.keySet().contains(wId.getWorkExternalIdentifierType().getValue())) {
            setError(wId.getWorkExternalIdentifierType(), "manualWork.id_invalid");
        }
    }
    return work;
}
Also used : Text(org.orcid.pojo.ajaxForm.Text) WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier) IdentifierType(org.orcid.pojo.IdentifierType) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with IdentifierType

use of org.orcid.pojo.IdentifierType in project ORCID-Source by ORCID.

the class IdentifierTypePOJOConverter method fromEntity.

public IdentifierType fromEntity(IdentifierTypeEntity entity) {
    IdentifierType id = new IdentifierType();
    id.setPutCode(entity.getId());
    id.setName(externalIdentifierTypeConverter.convertFrom(entity.getName(), null));
    id.setDeprecated(entity.getIsDeprecated());
    id.setResolutionPrefix(entity.getResolutionPrefix());
    id.setValidationRegex(entity.getValidationRegex());
    id.setDateCreated(new Date(entity.getDateCreated().getTime()));
    id.setLastModified(new Date(entity.getLastModified().getTime()));
    id.setSourceClient(entity.getSourceClient());
    id.setCaseSensitive(entity.getIsCaseSensitive());
    id.setPrimaryUse(entity.getPrimaryUse());
    return id;
}
Also used : IdentifierType(org.orcid.pojo.IdentifierType) Date(java.util.Date)

Example 8 with IdentifierType

use of org.orcid.pojo.IdentifierType in project ORCID-Source by ORCID.

the class IdentifierTypeManagerImpl method queryByPrefix.

/**
     * Queries the identifier name and description fields for words that START WITH query.
     * Returns an immutable list of matching types.
     * Null locale will result in Locale.ENGLISH
     * 
     */
@Override
@Cacheable("identifier-types-map-prefix")
public List<IdentifierType> queryByPrefix(String query, Locale loc) {
    Map<String, IdentifierType> results = new HashMap<String, IdentifierType>();
    Map<String, IdentifierType> types = fetchIdentifierTypesByAPITypeName(loc);
    //stick them in a trie so we can do a deep prefix search
    PatriciaTrie<Set<IdentifierType>> trie = new PatriciaTrie<Set<IdentifierType>>();
    for (String type : types.keySet()) {
        IdentifierType t = types.get(type);
        if (!trie.containsKey(t.getName().toLowerCase()))
            trie.put(t.getName().toLowerCase(), new HashSet<IdentifierType>());
        trie.get(t.getName().toLowerCase()).add(t);
        for (String s : t.getDescription().toLowerCase().split(" ")) {
            if (!trie.containsKey(s))
                trie.put(s, new HashSet<IdentifierType>());
            trie.get(s).add(t);
        }
    }
    //dedupe and sort
    SortedMap<String, Set<IdentifierType>> sorted = trie.prefixMap(query.toLowerCase());
    for (Set<IdentifierType> set : sorted.values()) {
        for (IdentifierType t : set) {
            if (!results.containsKey(t.getDescription().toLowerCase()))
                results.put(t.getDescription().toLowerCase(), t);
        }
    }
    //put anything that starts with query at the top of the list.
    Builder<IdentifierType> builder = new Builder<IdentifierType>();
    for (IdentifierType t : results.values()) {
        if (t.getDescription().toLowerCase().startsWith(query.toLowerCase())) {
            builder.add(t);
        }
    }
    for (IdentifierType t : results.values()) {
        if (!t.getDescription().toLowerCase().startsWith(query.toLowerCase())) {
            builder.add(t);
        }
    }
    return builder.build();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) PatriciaTrie(org.apache.commons.collections4.trie.PatriciaTrie) Builder(com.google.common.collect.ImmutableList.Builder) IdentifierType(org.orcid.pojo.IdentifierType) HashSet(java.util.HashSet) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 9 with IdentifierType

use of org.orcid.pojo.IdentifierType in project ORCID-Source by ORCID.

the class IdentifierTypeConverterTest method testFromPojo.

@Test
public void testFromPojo() {
    IdentifierType id = new IdentifierType();
    id.setPutCode(1l);
    id.setName("name-test");
    id.setDeprecated(true);
    id.setResolutionPrefix("prefix");
    id.setValidationRegex("validation");
    id.setDateCreated(new Date(10, 10, 10));
    id.setLastModified(new Date(11, 11, 11));
    ClientDetailsEntity client = new ClientDetailsEntity();
    client.setClientName("clientName");
    id.setSourceClient(client);
    IdentifierTypeEntity entity = new IdentifierTypePOJOConverter().fromPojo(id);
    assertEquals(Long.valueOf(1l), entity.getId());
    assertEquals("NAME_TEST", entity.getName());
    assertEquals(true, entity.getIsDeprecated());
    assertEquals("prefix", entity.getResolutionPrefix());
    assertEquals("validation", entity.getValidationRegex());
    assertEquals(new Date(10, 10, 10), entity.getDateCreated());
    assertEquals(new Date(11, 11, 11), entity.getLastModified());
    assertEquals("clientName", entity.getSourceClient().getClientName());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) IdentifierTypeEntity(org.orcid.persistence.jpa.entities.IdentifierTypeEntity) IdentifierTypePOJOConverter(org.orcid.core.adapter.impl.IdentifierTypePOJOConverter) IdentifierType(org.orcid.pojo.IdentifierType) Date(java.util.Date) BaseTest(org.orcid.core.BaseTest) Test(org.junit.Test)

Example 10 with IdentifierType

use of org.orcid.pojo.IdentifierType in project ORCID-Source by ORCID.

the class IdentifierApiServiceDelegatorTest method testviewIdentifierTypesWithLocale.

@Test
public void testviewIdentifierTypesWithLocale() {
    assertEquals(service.viewIdentifierTypes("es").getStatus(), 200);
    Response r = service.viewIdentifierTypes("es");
    @SuppressWarnings("unchecked") GenericEntity<List<IdentifierType>> types = (GenericEntity<List<IdentifierType>>) r.getEntity();
    Boolean found = false;
    for (IdentifierType t : types.getEntity()) {
        if (t.getName().equals("doi")) {
            assertEquals("doi: Identificador de objeto digital", t.getDescription());
            found = true;
        }
    }
    assertTrue("no description for DOI found", found);
}
Also used : Response(javax.ws.rs.core.Response) GenericEntity(javax.ws.rs.core.GenericEntity) ArrayList(java.util.ArrayList) List(java.util.List) IdentifierType(org.orcid.pojo.IdentifierType) Test(org.junit.Test)

Aggregations

IdentifierType (org.orcid.pojo.IdentifierType)14 Test (org.junit.Test)6 Date (java.util.Date)5 BaseTest (org.orcid.core.BaseTest)4 IdentifierTypeEntity (org.orcid.persistence.jpa.entities.IdentifierTypeEntity)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 Cacheable (org.springframework.cache.annotation.Cacheable)3 List (java.util.List)2 GenericEntity (javax.ws.rs.core.GenericEntity)2 Response (javax.ws.rs.core.Response)2 IdentifierTypePOJOConverter (org.orcid.core.adapter.impl.IdentifierTypePOJOConverter)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 Builder (com.google.common.collect.ImmutableList.Builder)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 SortedMap (java.util.SortedMap)1