Search in sources :

Example 1 with Statement

use of org.nextprot.commons.statements.Statement in project nextprot-api by calipho-sib.

the class EntryAnnotationBuilderTest method shouldThrowAnExceptionIfInModeStrictAndPublicationIsNotFound.

@Test(expected = NextProtException.class)
public void shouldThrowAnExceptionIfInModeStrictAndPublicationIsNotFound() {
    Statement sb1 = StatementBuilder.createNew().addField(StatementField.REFERENCE_DATABASE, "PubMed").addField(StatementField.REFERENCE_ACCESSION, "000").build();
    StatementAnnotationBuilder ab = StatementEntryAnnotationBuilder.newBuilder(terminologyService, publicationService, mainNamesService);
    ab.findPublicationId(sb1);
}
Also used : Statement(org.nextprot.commons.statements.Statement) Test(org.junit.Test)

Example 2 with Statement

use of org.nextprot.commons.statements.Statement in project nextprot-api by calipho-sib.

the class EntryAnnotationBuilderTest method shouldReturnOneSingleAnnotationIfTheInfoIsTheSameAndItIsComingFromDifferentSources.

@Test
public void shouldReturnOneSingleAnnotationIfTheInfoIsTheSameAndItIsComingFromDifferentSources() {
    Statement sb1 = StatementBuilder.createNew().addCompulsaryFields("NX_P01308", "NX_P01308", "go-cellular-component", QualityQualifier.GOLD).addCvTerm("go-xxx", "nucleus", "go-cellular-component-cv").addField(StatementField.REFERENCE_DATABASE, "PubMed").addField(StatementField.REFERENCE_ACCESSION, "123").addTargetIsoformsField(new TargetIsoformSet()).addField(StatementField.EVIDENCE_CODE, "ECO:00001").addField(StatementField.ASSIGNED_BY, "TUTU").addSourceInfo("CAVA-VP0920190912", "BioEditor").buildWithAnnotationHash(AnnotationType.ENTRY);
    Statement sb2 = StatementBuilder.createNew().addCompulsaryFields("NX_P01308", "NX_P01308", "go-cellular-component", QualityQualifier.GOLD).addField(StatementField.REFERENCE_DATABASE, "PubMed").addField(StatementField.REFERENCE_ACCESSION, "123").addTargetIsoformsField(new TargetIsoformSet()).addCvTerm("go-xxx", "nucleus", "go-cellular-component-cv").addField(StatementField.EVIDENCE_CODE, "ECO:00001").addField(StatementField.ASSIGNED_BY, "TOTO").addSourceInfo("HPA2222", "HPA").buildWithAnnotationHash(AnnotationType.ENTRY);
    List<Statement> statements = Arrays.asList(sb1, sb2);
    Annotation annotation = newAnnotationBuilder().buildAnnotation("NX_P01308", statements);
    Assert.assertEquals(annotation.getAPICategory(), AnnotationCategory.GO_CELLULAR_COMPONENT);
    Assert.assertEquals(annotation.getEvidences().size(), 2);
    Assert.assertEquals(annotation.getEvidences().get(0).getEvidenceCodeName(), "eco-name-1");
}
Also used : Statement(org.nextprot.commons.statements.Statement) TargetIsoformSet(org.nextprot.commons.statements.TargetIsoformSet) Annotation(org.nextprot.api.core.domain.annotation.Annotation) Test(org.junit.Test)

Example 3 with Statement

use of org.nextprot.commons.statements.Statement in project nextprot-api by calipho-sib.

the class JDBCStatementLoaderServiceImpl method load.

private void load(Set<Statement> statements, String tableName, NextProtSource source) throws SQLException {
    java.sql.Statement deleteStatement = null;
    PreparedStatement pstmt = null;
    try (Connection conn = dataSourceServiceLocator.getStatementsDataSource().getConnection()) {
        deleteStatement = conn.createStatement();
        deleteStatement.addBatch("DELETE FROM nxflat." + tableName + " WHERE SOURCE = '" + source.getSourceName() + "'");
        String columnNames = StringUtils.mkString(StatementField.values(), "", ",", "");
        List<String> bindVariablesList = new ArrayList<>();
        for (int i = 0; i < StatementField.values().length; i++) {
            bindVariablesList.add("?");
        }
        String bindVariables = StringUtils.mkString(bindVariablesList, "", ",", "");
        pstmt = conn.prepareStatement("INSERT INTO nxflat." + tableName + " (" + columnNames + ") VALUES ( " + bindVariables + ")");
        for (Statement s : statements) {
            for (int i = 0; i < StatementField.values().length; i++) {
                StatementField sf = StatementField.values()[i];
                String value = null;
                if (StatementField.SOURCE.equals(sf)) {
                    value = source.getSourceName();
                } else
                    value = s.getValue(sf);
                if (value != null) {
                    pstmt.setString(i + 1, value.replace("'", "''"));
                } else {
                    pstmt.setNull(i + 1, java.sql.Types.VARCHAR);
                }
            }
            pstmt.addBatch();
        }
        deleteStatement.executeBatch();
        pstmt.executeBatch();
    } finally {
        if (deleteStatement != null) {
            deleteStatement.close();
        }
        if (pstmt != null) {
            pstmt.close();
        }
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(org.nextprot.commons.statements.Statement) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) StatementField(org.nextprot.commons.statements.StatementField)

Example 4 with Statement

use of org.nextprot.commons.statements.Statement in project nextprot-api by calipho-sib.

the class StatementExtractorBase method deserialize.

protected Set<Statement> deserialize(InputStream content) {
    ObjectMapper mapper = new ObjectMapper();
    Set<Statement> obj = null;
    try {
        obj = mapper.readValue(content, new TypeReference<Set<Statement>>() {
        });
    } catch (IOException e) {
        throw new NextProtException(e);
    }
    return obj;
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) Statement(org.nextprot.commons.statements.Statement) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with Statement

use of org.nextprot.commons.statements.Statement in project nextprot-api by calipho-sib.

the class StatementDaoImpl method findStatementsByAnnotIsoIds.

@Override
public List<Statement> findStatementsByAnnotIsoIds(AnnotationType type, List<String> idList) {
    List<Statement> statements = new ArrayList<>();
    if (idList == null || idList.isEmpty())
        return statements;
    int limit = 1000;
    // Make a distinct list, could use set as well?
    List<String> ids = idList.parallelStream().distinct().collect(Collectors.toList());
    for (int i = 0; i < ids.size(); i += limit) {
        int toLimit = (i + limit > ids.size()) ? ids.size() : i + limit;
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("ids", ids.subList(i, toLimit));
        String sql = getSQL(type, "statements-by-annotation-id");
        List<Statement> statementsAux = new NamedParameterJdbcTemplate(dsLocator.getStatementsDataSource()).query(sql, params, new StatementMapper());
        statements.addAll(statementsAux);
    }
    return statements;
}
Also used : HashMap(java.util.HashMap) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) Statement(org.nextprot.commons.statements.Statement) ArrayList(java.util.ArrayList)

Aggregations

Statement (org.nextprot.commons.statements.Statement)16 Test (org.junit.Test)11 StatementETLBaseUnitTest (org.nextprot.api.etl.statement.StatementETLBaseUnitTest)6 Annotation (org.nextprot.api.core.domain.annotation.Annotation)4 ReportBuilder (org.nextprot.api.etl.service.impl.StatementETLServiceImpl.ReportBuilder)4 StatementField (org.nextprot.commons.statements.StatementField)4 TargetIsoformSet (org.nextprot.commons.statements.TargetIsoformSet)4 Collectors (java.util.stream.Collectors)3 NextProtException (org.nextprot.api.commons.exception.NextProtException)3 Supplier (com.google.common.base.Supplier)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Logger (org.apache.log4j.Logger)2 AnnotationCategory (org.nextprot.api.commons.constants.AnnotationCategory)2 IdentifierOffset (org.nextprot.api.commons.constants.IdentifierOffset)2 StringUtils (org.nextprot.api.commons.utils.StringUtils)2 BioObject (org.nextprot.api.core.domain.BioObject)2 BioType (org.nextprot.api.core.domain.BioObject.BioType)2