Search in sources :

Example 1 with OWLAnnotation

use of org.nextprot.api.rdf.domain.OWLAnnotation in project nextprot-api by calipho-sib.

the class SchemaDaoImpl method findAllAnnotation.

@Override
public List<OWLAnnotation> findAllAnnotation() {
    // get description for annotations that exist in db
    AnnotationCategory[] cats = AnnotationCategory.values();
    List<Long> typeIds = new ArrayList<Long>();
    for (AnnotationCategory cat : cats) typeIds.add(new Long(cat.getDbId()));
    SqlParameterSource params = new MapSqlParameterSource("typeIds", typeIds);
    List<NameDescr> nds = new NamedParameterJdbcTemplate(dsLocator.getDataSource()).query(sqlDictionary.getSQLQuery("schema-instantiated-annotation-list"), params, new ParameterizedRowMapper<NameDescr>() {

        @Override
        public NameDescr mapRow(ResultSet rs, int row) throws SQLException {
            NameDescr nd = new NameDescr(rs.getString("cv_name"), rs.getString("description"));
            // System.out.println("rs.cv_name=" + nd.name + " description="+ nd.descr);
            return nd;
        }
    });
    // inject descriptions found in db into the OWLAnnotationCategory enum values
    for (NameDescr nd : nds) {
        AnnotationCategory m = AnnotationCategory.getByDbAnnotationTypeName(nd.name);
        // System.out.println("before descr: " + m.toString());
        m.setDescription(nd.descr);
    // System.out.println("after descr: " + m.toString());
    // AnnotationCategory.getByDbAnnotationTypeName(nd.name).setDescription(nd.descr);
    }
    // encapsulate OWLAnnotationCategory into OWLAnnotation to be compatible with the rest
    List<OWLAnnotation> annotations = new ArrayList<OWLAnnotation>();
    for (AnnotationCategory cat : AnnotationCategory.values()) {
        annotations.add(new OWLAnnotation(cat));
    }
    return annotations;
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) SQLException(java.sql.SQLException) OWLAnnotation(org.nextprot.api.rdf.domain.OWLAnnotation) ArrayList(java.util.ArrayList) AnnotationCategory(org.nextprot.api.commons.constants.AnnotationCategory) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ResultSet(java.sql.ResultSet)

Aggregations

ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 AnnotationCategory (org.nextprot.api.commons.constants.AnnotationCategory)1 OWLAnnotation (org.nextprot.api.rdf.domain.OWLAnnotation)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)1 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)1