Search in sources :

Example 1 with PublicationRep

use of cbit.vcell.modeldb.PublicationRep in project vcell by virtualcell.

the class PublicationServerResource method getPublicationRepresentation.

private static PublicationRepresentation getPublicationRepresentation(RestDatabaseService restDatabaseService, User vcellUser, KeyValue pubID) {
    // RestDatabaseService restDatabaseService = ((VCellApiApplication)getApplication()).getRestDatabaseService();
    try {
        PublicationRep publicationRep = restDatabaseService.getPublicationRep(pubID, vcellUser);
        PublicationRepresentation publicationRepresentation = new PublicationRepresentation(publicationRep);
        return publicationRepresentation;
    } catch (PermissionException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "publication not found");
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
// }
}
Also used : PermissionException(org.vcell.util.PermissionException) PublicationRepresentation(org.vcell.rest.common.PublicationRepresentation) PublicationRep(cbit.vcell.modeldb.PublicationRep) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Example 2 with PublicationRep

use of cbit.vcell.modeldb.PublicationRep in project vcell by virtualcell.

the class RestDatabaseService method getPublicationRep.

public PublicationRep getPublicationRep(KeyValue pubKey, User vcellUser) throws SQLException, ObjectNotFoundException, DataAccessException {
    if (vcellUser == null) {
        vcellUser = VCellApiApplication.DUMMY_USER;
    }
    ArrayList<String> conditions = new ArrayList<String>();
    if (pubKey != null) {
        conditions.add("(" + PublicationTable.table.id.getQualifiedColName() + " = " + pubKey.toString() + ")");
    } else {
        throw new RuntimeException("bioModelID not specified");
    }
    StringBuffer conditionsBuffer = new StringBuffer();
    for (String condition : conditions) {
        if (conditionsBuffer.length() > 0) {
            conditionsBuffer.append(" AND ");
        }
        conditionsBuffer.append(condition);
    }
    PublicationRep[] publicationReps = databaseServerImpl.getPublicationReps(vcellUser, conditionsBuffer.toString(), null);
    if (publicationReps == null || publicationReps.length != 1) {
        throw new ObjectNotFoundException("failed to get publication");
    }
    return publicationReps[0];
}
Also used : PublicationRep(cbit.vcell.modeldb.PublicationRep) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ArrayList(java.util.ArrayList) BigString(org.vcell.util.BigString)

Example 3 with PublicationRep

use of cbit.vcell.modeldb.PublicationRep in project vcell by virtualcell.

the class RestDatabaseService method query.

public PublicationRep[] query(PublicationsServerResource resource, User vcellUser) throws SQLException, DataAccessException {
    if (vcellUser == null) {
        vcellUser = VCellApiApplication.DUMMY_USER;
    }
    Long pubID = resource.getLongQueryValue(PublicationsServerResource.PARAM_PUB_ID);
    // it is ok if the orderBy is null;
    String orderByParam = resource.getQueryValue(PublicationsServerResource.PARAM_ORDERBY);
    ArrayList<String> conditions = new ArrayList<String>();
    java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss", java.util.Locale.US);
    if (pubID != null) {
        conditions.add("(" + PublicationTable.table.id.getQualifiedColName() + " = " + pubID + ")");
    }
    StringBuffer conditionsBuffer = new StringBuffer();
    for (String condition : conditions) {
        if (conditionsBuffer.length() > 0) {
            conditionsBuffer.append(" AND ");
        }
        conditionsBuffer.append(condition);
    }
    // default
    OrderBy orderBy = OrderBy.year_desc;
    if (orderByParam != null) {
        if (orderByParam.equals(BiomodelsServerResource.PARAM_ORDERBY_YEAR_ASC)) {
            orderBy = OrderBy.year_asc;
        } else if (orderByParam.equals(BiomodelsServerResource.PARAM_ORDERBY_YEAR_DESC)) {
            orderBy = OrderBy.year_desc;
        } else if (orderByParam.equals(BiomodelsServerResource.PARAM_ORDERBY_NAME_ASC)) {
            orderBy = OrderBy.name_asc;
        } else if (orderByParam.equals(BiomodelsServerResource.PARAM_ORDERBY_NAME_DESC)) {
            orderBy = OrderBy.name_desc;
        }
    }
    PublicationRep[] publicationReps = databaseServerImpl.getPublicationReps(vcellUser, conditionsBuffer.toString(), orderBy);
    return publicationReps;
}
Also used : OrderBy(cbit.vcell.modeldb.DatabaseServerImpl.OrderBy) PublicationRep(cbit.vcell.modeldb.PublicationRep) ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) BigString(org.vcell.util.BigString) SimulationContext(cbit.vcell.mapping.SimulationContext) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with PublicationRep

use of cbit.vcell.modeldb.PublicationRep in project vcell by virtualcell.

the class PublicationServerResource method getPublicationRepresentation.

private PublicationRepresentation getPublicationRepresentation(User vcellUser) {
    // if (!application.authenticate(getRequest(), getResponse())){
    // // not authenticated
    // return new SimulationTaskRepresentation[0];
    // }else{
    RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
    try {
        PublicationRep publicationRep = restDatabaseService.query(this, vcellUser);
        PublicationRepresentation publicationRepresentation = new PublicationRepresentation(publicationRep);
        return publicationRepresentation;
    } catch (PermissionException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "publication not found");
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
// }
}
Also used : PermissionException(org.vcell.util.PermissionException) PublicationRepresentation(org.vcell.rest.common.PublicationRepresentation) PublicationRep(cbit.vcell.modeldb.PublicationRep) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Example 5 with PublicationRep

use of cbit.vcell.modeldb.PublicationRep in project vcell by virtualcell.

the class PublicationsServerResource method getPublicationRepresentations.

private PublicationRepresentation[] getPublicationRepresentations(User vcellUser) {
    ArrayList<PublicationRepresentation> publicationRepresentations = new ArrayList<PublicationRepresentation>();
    RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
    try {
        PublicationRep[] publicationReps = restDatabaseService.query(this, vcellUser);
        for (PublicationRep publicationRep : publicationReps) {
            PublicationRepresentation publicationRepresentation = new PublicationRepresentation(publicationRep);
            publicationRepresentations.add(publicationRepresentation);
        }
    } catch (PermissionException ee) {
        ee.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "not authorized");
    } catch (DataAccessException | SQLException | ExpressionException e) {
        e.printStackTrace();
        throw new RuntimeException("failed to retrieve biomodels from VCell Database : " + e.getMessage());
    }
    return publicationRepresentations.toArray(new PublicationRepresentation[0]);
}
Also used : PermissionException(org.vcell.util.PermissionException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ExpressionException(cbit.vcell.parser.ExpressionException) PublicationRepresentation(org.vcell.rest.common.PublicationRepresentation) PublicationRep(cbit.vcell.modeldb.PublicationRep) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

PublicationRep (cbit.vcell.modeldb.PublicationRep)6 ResourceException (org.restlet.resource.ResourceException)4 PublicationRepresentation (org.vcell.rest.common.PublicationRepresentation)4 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)4 PermissionException (org.vcell.util.PermissionException)4 ArrayList (java.util.ArrayList)3 VCellApiApplication (org.vcell.rest.VCellApiApplication)3 SimpleDateFormat (java.text.SimpleDateFormat)2 BigString (org.vcell.util.BigString)2 SimulationContext (cbit.vcell.mapping.SimulationContext)1 BioModelReferenceRep (cbit.vcell.modeldb.BioModelReferenceRep)1 OrderBy (cbit.vcell.modeldb.DatabaseServerImpl.OrderBy)1 MathModelReferenceRep (cbit.vcell.modeldb.MathModelReferenceRep)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 Configuration (freemarker.template.Configuration)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Form (org.restlet.data.Form)1 TemplateRepresentation (org.restlet.ext.freemarker.TemplateRepresentation)1 Representation (org.restlet.representation.Representation)1