Search in sources :

Example 41 with NextProtException

use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.

the class SolrIndexer method clearDatabase.

public void clearDatabase(String query) {
    try {
        if (query != null && !query.equals(""))
            solrServer.deleteByQuery(query);
        else
            solrServer.deleteByQuery("*:*");
        solrServer.commit();
        solrServer.optimize();
    } catch (SolrServerException | IOException e) {
        throw new NextProtException(e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 42 with NextProtException

use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.

the class SolrIndexer method commit.

public void commit() {
    try {
        solrServer.commit();
        solrServer.optimize();
    } catch (SolrServerException | IOException e) {
        throw new NextProtException(e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 43 with NextProtException

use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.

the class UserDaoImpl method updateUser.

@Override
public void updateUser(User src) {
    final String UPDATE_SQL = sqlDictionary.getSQLQuery("update-user");
    MapSqlParameterSource namedParameters = new MapSqlParameterSource();
    // key to identify application to be updated
    namedParameters.addValue("user_id", src.getId());
    // values to update
    namedParameters.addValue("user_name", src.getUsername());
    namedParameters.addValue("first_name", src.getFirstName());
    namedParameters.addValue("last_name", src.getLastName());
    NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource());
    int affectedRows = jdbcTemplate.update(UPDATE_SQL, namedParameters);
    if (affectedRows != 1) {
        String msg = "oops something wrong occurred" + affectedRows + " rows were affected instead of only 1.";
        Logger.error(msg);
        throw new NextProtException(msg);
    }
    if (src.getAuthorities() != null && !src.getAuthorities().isEmpty()) {
        // 1. delete all roles for this user if roles exist in user_roles table of src
        deleteUserRoles(src.getId());
        // 2. insert roles with insertUserRoles(src.getKey(), src.getRoles())
        insertUserAuthorities(src.getId(), src.getAuthorities());
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Example 44 with NextProtException

use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.

the class UserQueryDaoImpl method updateUserQuery.

@Override
public void updateUserQuery(final UserQuery src) {
    final String UPDATE_SQL = sqlDictionary.getSQLQuery("update-user-query");
    MapSqlParameterSource namedParameters = new MapSqlParameterSource();
    // key to identify query to update
    namedParameters.addValue("query_id", src.getUserQueryId());
    // values to update
    namedParameters.addValue("title", src.getTitle());
    namedParameters.addValue("description", src.getDescription());
    namedParameters.addValue("sparql", src.getSparql());
    namedParameters.addValue("published", src.getPublished() ? 'Y' : 'N');
    NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource());
    int affectedRows = jdbcTemplate.update(UPDATE_SQL, namedParameters);
    if (affectedRows != 1) {
        String msg = "oops something wrong occurred" + affectedRows + " rows were affected instead of only 1.";
        Logger.error(msg);
        throw new NextProtException(msg);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Example 45 with NextProtException

use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.

the class UserApplicationDaoImpl method updateUserApplication.

@Override
public void updateUserApplication(final UserApplication src) {
    final String UPDATE_SQL = sqlDictionary.getSQLQuery("update-user-application");
    MapSqlParameterSource namedParameters = new MapSqlParameterSource();
    // key to identify application to be updated
    namedParameters.addValue("application_id", src.getId());
    // values to update
    namedParameters.addValue("application_name", src.getName());
    namedParameters.addValue("description", src.getDescription());
    namedParameters.addValue("organisation", src.getOrganisation());
    namedParameters.addValue("responsible_name", src.getResponsibleName());
    namedParameters.addValue("responsible_email", src.getResponsibleEmail());
    namedParameters.addValue("website", src.getWebsite());
    namedParameters.addValue("token", src.getToken());
    namedParameters.addValue("status", src.getStatus());
    namedParameters.addValue("user_data_access", src.getUserDataAccess());
    namedParameters.addValue("origins", src.getOrigins());
    NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource());
    int affectedRows = jdbcTemplate.update(UPDATE_SQL, namedParameters);
    if (affectedRows != 1) {
        String msg = "something wrong occurred: " + affectedRows + " rows were affected (expected=1).";
        Logger.error(msg);
        throw new NextProtException(msg);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Aggregations

NextProtException (org.nextprot.api.commons.exception.NextProtException)68 IOException (java.io.IOException)30 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ApiMethod (org.jsondoc.core.annotation.ApiMethod)8 OutputStream (java.io.OutputStream)7 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)7 Cacheable (org.springframework.cache.annotation.Cacheable)6 Isoform (org.nextprot.api.core.domain.Isoform)5 SolrServerException (org.apache.solr.client.solrj.SolrServerException)4 Annotation (org.nextprot.api.core.domain.annotation.Annotation)4 NextprotMediaType (org.nextprot.api.core.service.export.format.NextprotMediaType)4 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)4 java.util (java.util)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 CvTerm (org.nextprot.api.core.domain.CvTerm)3 AnnotationVariant (org.nextprot.api.core.domain.annotation.AnnotationVariant)3 Query (org.nextprot.api.solr.Query)3 SearchResult (org.nextprot.api.solr.SearchResult)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2