Search in sources :

Example 1 with TermLookupServiceConfigurationException

use of org.eol.globi.service.TermLookupServiceConfigurationException in project eol-globi-data by jhpoelen.

the class InteractTypeMapperFactoryImpl method buildTypeMap.

public static Map<String, InteractType> buildTypeMap(LabeledCSVParser labeledCSVParser, String providedInteractionTypeIdColumnName, String providedInteractionTypeNameColumnName, String mappedInteractionTypeIdColumnName) throws TermLookupServiceException, IOException {
    Map<String, InteractType> typeMap = new TreeMap<>();
    List<String> columnNames = Arrays.asList(labeledCSVParser.getLabels());
    assertColumnNamePresent(columnNames, providedInteractionTypeNameColumnName);
    assertColumnNamePresent(columnNames, providedInteractionTypeIdColumnName);
    assertColumnNamePresent(columnNames, mappedInteractionTypeIdColumnName);
    while (labeledCSVParser.getLine() != null) {
        String provideInteractionIdString = labeledCSVParser.getValueByLabel(providedInteractionTypeIdColumnName);
        String providedInteractionId = StringUtils.trim(provideInteractionIdString);
        String provideInteractionNameString = labeledCSVParser.getValueByLabel(providedInteractionTypeNameColumnName);
        String providedInteractionName = InteractUtil.normalizeInteractionName(StringUtils.lowerCase(provideInteractionNameString));
        String interactionTypeId = StringUtils.trim(labeledCSVParser.getValueByLabel(mappedInteractionTypeIdColumnName));
        InteractType interactType = InteractType.typeOf(interactionTypeId);
        if (interactType == null) {
            throw new TermLookupServiceConfigurationException("failed to map interaction type to [" + interactionTypeId + "] on line [" + labeledCSVParser.lastLineNumber() + "]: interaction type unknown to GloBI");
        } else {
            if (StringUtils.isBlank(providedInteractionId) && StringUtils.isBlank(providedInteractionName)) {
                if (typeMap.containsKey("")) {
                    throw new TermLookupServiceConfigurationException("only one default/blank interaction type can be defined, but found duplicate on line [" + labeledCSVParser.lastLineNumber() + "]: [" + StringUtils.join(labeledCSVParser.getLine(), "|") + "]");
                }
                typeMap.put("", interactType);
            } else {
                if (StringUtils.isNotBlank(providedInteractionId)) {
                    setOrThrow(typeMap, providedInteractionId, interactType);
                }
                if (StringUtils.isNotBlank(providedInteractionName)) {
                    setOrThrow(typeMap, providedInteractionId, providedInteractionName, interactType);
                }
            }
        }
    }
    return typeMap;
}
Also used : InteractType(org.eol.globi.domain.InteractType) TermLookupServiceConfigurationException(org.eol.globi.service.TermLookupServiceConfigurationException) TreeMap(java.util.TreeMap)

Example 2 with TermLookupServiceConfigurationException

use of org.eol.globi.service.TermLookupServiceConfigurationException in project eol-globi-data by jhpoelen.

the class InteractTypeMapperFactoryWithFallback method create.

@Override
public InteractTypeMapper create() throws TermLookupServiceException {
    InteractTypeMapper mapper = null;
    TermLookupServiceException lastException = null;
    for (InteractTypeMapperFactory factory : factoryAlternatives) {
        try {
            mapper = factory.create();
            if (mapper != null) {
                break;
            }
        } catch (TermLookupServiceConfigurationException ex) {
            throw ex;
        } catch (TermLookupServiceException ex) {
            lastException = ex;
        }
    }
    if (mapper == null) {
        throw lastException == null ? new TermLookupServiceException("failed to create interaction type mapper") : lastException;
    }
    return mapper;
}
Also used : TermLookupServiceException(org.eol.globi.service.TermLookupServiceException) TermLookupServiceConfigurationException(org.eol.globi.service.TermLookupServiceConfigurationException)

Example 3 with TermLookupServiceConfigurationException

use of org.eol.globi.service.TermLookupServiceConfigurationException in project eol-globi-data by jhpoelen.

the class InteractTypeMapperFactoryWithFallbackTest method throwOnConfigurationIssueForFirstMapper.

@Test(expected = TermLookupServiceConfigurationException.class)
public void throwOnConfigurationIssueForFirstMapper() throws TermLookupServiceException {
    InteractTypeMapperFactory secondFactory = Mockito.mock(InteractTypeMapperFactory.class);
    InteractTypeMapper mapper = Mockito.mock(InteractTypeMapper.class);
    when(secondFactory.create()).thenReturn(mapper);
    InteractTypeMapperFactory firstFactory = Mockito.mock(InteractTypeMapperFactory.class);
    when(firstFactory.create()).thenThrow(new TermLookupServiceConfigurationException("kaboom!"));
    InteractTypeMapper interactTypeMapper = new InteractTypeMapperFactoryWithFallback(firstFactory, secondFactory).create();
    assertThat(interactTypeMapper, is(mapper));
}
Also used : TermLookupServiceConfigurationException(org.eol.globi.service.TermLookupServiceConfigurationException) Test(org.junit.Test)

Aggregations

TermLookupServiceConfigurationException (org.eol.globi.service.TermLookupServiceConfigurationException)3 TreeMap (java.util.TreeMap)1 InteractType (org.eol.globi.domain.InteractType)1 TermLookupServiceException (org.eol.globi.service.TermLookupServiceException)1 Test (org.junit.Test)1