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;
}
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;
}
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();
}
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());
}
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);
}
Aggregations