Search in sources :

Example 1 with OrderBy

use of cbit.vcell.modeldb.DatabaseServerImpl.OrderBy in project vcell by virtualcell.

the class RestDatabaseService method query.

public BioModelRep[] query(BiomodelsServerResource resource, User vcellUser) throws SQLException, DataAccessException {
    if (vcellUser == null) {
        vcellUser = VCellApiApplication.DUMMY_USER;
    }
    String bioModelName = resource.getQueryValue(BiomodelsServerResource.PARAM_BM_NAME);
    Long bioModelID = resource.getLongQueryValue(BiomodelsServerResource.PARAM_BM_ID);
    Long savedLow = resource.getLongQueryValue(BiomodelsServerResource.PARAM_SAVED_LOW);
    Long savedHigh = resource.getLongQueryValue(BiomodelsServerResource.PARAM_SAVED_HIGH);
    Long startRowParam = resource.getLongQueryValue(BiomodelsServerResource.PARAM_START_ROW);
    Long maxRowsParam = resource.getLongQueryValue(BiomodelsServerResource.PARAM_MAX_ROWS);
    // it is ok if the category is null;
    String categoryParam = resource.getQueryValue(BiomodelsServerResource.PARAM_CATEGORY);
    // it is ok if the ownerName is null;
    String ownerParam = resource.getQueryValue(BiomodelsServerResource.PARAM_BM_OWNER);
    // it is ok if the orderBy is null;
    String orderByParam = resource.getQueryValue(BiomodelsServerResource.PARAM_ORDERBY);
    // default
    int startRow = 1;
    if (startRowParam != null) {
        startRow = startRowParam.intValue();
    }
    // default
    int maxRows = 10;
    if (maxRowsParam != null) {
        maxRows = maxRowsParam.intValue();
    }
    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 (savedLow != null) {
        conditions.add("(" + BioModelTable.table.versionDate.getQualifiedColName() + " >= to_date('" + df.format(new Date(savedLow)) + "', 'mm/dd/yyyy HH24:MI:SS'))");
    }
    if (savedHigh != null) {
        conditions.add("(" + BioModelTable.table.versionDate.getQualifiedColName() + " <= to_date('" + df.format(new Date(savedHigh)) + "', 'mm/dd/yyyy HH24:MI:SS'))");
    }
    if (bioModelName != null && bioModelName.trim().length() > 0) {
        String pattern = bioModelName.trim();
        pattern = pattern.replace("  ", " ");
        pattern = pattern.replace("(", " ");
        pattern = pattern.replace(")", " ");
        pattern = pattern.replace("'", " ");
        pattern = pattern.replace("\"", " ");
        pattern = pattern.replace("*", "%");
        pattern = "%" + pattern + "%";
        pattern = pattern.replace("%%", "%");
        conditions.add("(" + "lower(" + BioModelTable.table.name.getQualifiedColName() + ")" + " like " + "lower('" + pattern + "')" + ")");
    }
    if (bioModelID != null) {
        conditions.add("(" + BioModelTable.table.id.getQualifiedColName() + " = " + bioModelID + ")");
    }
    // 
    if (categoryParam == null && ownerParam != null) {
        if (ownerParam.equals(VCellApiApplication.PSEUDOOWNER_PUBLIC)) {
            categoryParam = VCellApiApplication.CATEGORY_PUBLIC;
            ownerParam = null;
        } else if (ownerParam.equals(VCellApiApplication.PSEUDOOWNER_EDUCATION)) {
            categoryParam = VCellApiApplication.CATEGORY_EDUCATION;
            ownerParam = null;
        } else if (ownerParam.equals(VCellApiApplication.PSEUDOOWNER_SHARED)) {
            categoryParam = VCellApiApplication.CATEGORY_SHARED;
            ownerParam = null;
        } else if (ownerParam.equals(VCellApiApplication.PSEUDOOWNER_TUTORIAL)) {
            categoryParam = VCellApiApplication.CATEGORY_TUTORIAL;
            ownerParam = null;
        } else {
            categoryParam = VCellApiApplication.CATEGORY_ALL;
        }
    } else if (categoryParam == null && ownerParam == null) {
        categoryParam = VCellApiApplication.CATEGORY_ALL;
    }
    if (categoryParam.equals(VCellApiApplication.CATEGORY_MINE)) {
        // 
        // return all models owned by me (none if not authenticated).
        // 
        conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " = '" + vcellUser.getName() + "')");
    } else if (categoryParam.equals(VCellApiApplication.CATEGORY_PUBLIC)) {
        // 
        // public models that aren't "Tutorial" or "Education"
        // 
        // we will display all public models (even if owned by this user)
        // 
        conditions.add("(" + BioModelTable.table.privacy.getQualifiedColName() + " = " + GroupAccess.GROUPACCESS_ALL + ")");
        if (ownerParam != null && ownerParam.trim().length() > 0) {
            conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " = '" + ownerParam + "')");
        }
        conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " != '" + VCellApiApplication.USERNAME_TUTORIAL + "')");
        conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " != '" + VCellApiApplication.USERNAME_EDUCATION + "')");
    } else if (categoryParam.equals(VCellApiApplication.CATEGORY_EDUCATION)) {
        // 
        // public models from "Education"
        // 
        conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " = '" + VCellApiApplication.USERNAME_EDUCATION + "')");
        conditions.add("(" + BioModelTable.table.privacy.getQualifiedColName() + " = " + GroupAccess.GROUPACCESS_ALL + ")");
    } else if (categoryParam.equals(VCellApiApplication.CATEGORY_TUTORIAL)) {
        // 
        // public models from "tutorial"
        // 
        conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " = '" + VCellApiApplication.USERNAME_TUTORIAL + "')");
        conditions.add("(" + BioModelTable.table.privacy.getQualifiedColName() + " = " + GroupAccess.GROUPACCESS_ALL + ")");
    } else if (categoryParam.equals(VCellApiApplication.CATEGORY_SHARED)) {
        // 
        if (!vcellUser.compareEqual(VCellApiApplication.DUMMY_USER)) {
            conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " != '" + vcellUser.getName() + "')");
        }
        if (ownerParam != null && ownerParam.trim().length() > 0) {
            conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " = '" + ownerParam + "')");
        }
        conditions.add("(" + BioModelTable.table.privacy.getQualifiedColName() + " != " + GroupAccess.GROUPACCESS_ALL + ")");
        conditions.add("(" + BioModelTable.table.privacy.getQualifiedColName() + " != " + GroupAccess.GROUPACCESS_NONE + ")");
    } else if (categoryParam.equals(VCellApiApplication.CATEGORY_ALL)) {
        // 
        if (ownerParam != null && ownerParam.length() > 0) {
            conditions.add("(" + UserTable.table.userid.getQualifiedColName() + " = '" + ownerParam + "')");
        }
    }
    StringBuffer conditionsBuffer = new StringBuffer();
    for (String condition : conditions) {
        if (conditionsBuffer.length() > 0) {
            conditionsBuffer.append(" AND ");
        }
        conditionsBuffer.append(condition);
    }
    // default
    OrderBy orderBy = OrderBy.date_desc;
    if (orderByParam != null) {
        if (orderByParam.equals(BiomodelsServerResource.PARAM_ORDERBY_DATE_ASC)) {
            orderBy = OrderBy.date_asc;
        } else if (orderByParam.equals(BiomodelsServerResource.PARAM_ORDERBY_DATE_DESC)) {
            orderBy = OrderBy.date_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;
        }
    }
    BioModelRep[] bioModelReps = databaseServerImpl.getBioModelReps(vcellUser, conditionsBuffer.toString(), orderBy, startRow, maxRows);
    for (BioModelRep bioModelRep : bioModelReps) {
        KeyValue[] simContextKeys = bioModelRep.getSimContextKeyList();
        for (KeyValue scKey : simContextKeys) {
            SimContextRep scRep = getSimContextRep(scKey);
            if (scRep != null) {
                bioModelRep.addSimContextRep(scRep);
            }
        }
        KeyValue[] simulationKeys = bioModelRep.getSimKeyList();
        for (KeyValue simKey : simulationKeys) {
            SimulationRep simulationRep = getSimulationRep(simKey);
            if (simulationRep != null) {
                bioModelRep.addSimulationRep(simulationRep);
            }
        }
    }
    return bioModelReps;
}
Also used : OrderBy(cbit.vcell.modeldb.DatabaseServerImpl.OrderBy) KeyValue(org.vcell.util.document.KeyValue) ArrayList(java.util.ArrayList) BioModelRep(cbit.vcell.modeldb.BioModelRep) BigString(org.vcell.util.BigString) Date(java.util.Date) SimulationContext(cbit.vcell.mapping.SimulationContext) SimContextRep(cbit.vcell.modeldb.SimContextRep) SimulationRep(cbit.vcell.modeldb.SimulationRep)

Example 2 with OrderBy

use of cbit.vcell.modeldb.DatabaseServerImpl.OrderBy 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) BigString(org.vcell.util.BigString) SimulationContext(cbit.vcell.mapping.SimulationContext)

Aggregations

SimulationContext (cbit.vcell.mapping.SimulationContext)2 OrderBy (cbit.vcell.modeldb.DatabaseServerImpl.OrderBy)2 ArrayList (java.util.ArrayList)2 BigString (org.vcell.util.BigString)2 BioModelRep (cbit.vcell.modeldb.BioModelRep)1 PublicationRep (cbit.vcell.modeldb.PublicationRep)1 SimContextRep (cbit.vcell.modeldb.SimContextRep)1 SimulationRep (cbit.vcell.modeldb.SimulationRep)1 Date (java.util.Date)1 KeyValue (org.vcell.util.document.KeyValue)1