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