Search in sources :

Example 1 with SimContextRep

use of cbit.vcell.modeldb.SimContextRep 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 SimContextRep

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

the class SimulationRepresentation method getBioModelLink.

private static BioModelLink getBioModelLink(BioModelRep bioModelRep, SimulationRep simulationRep) {
    SimContextRep simContextRep = bioModelRep.getSimContextRepFromMathKey(simulationRep.getMathKey());
    BioModelLink bioModelLink = new BioModelLink(bioModelRep.getBmKey().toString(), bioModelRep.getBranchID().toString(), bioModelRep.getName(), (simContextRep != null) ? (simContextRep.getScKey().toString()) : null, (simContextRep != null) ? (simContextRep.getBranchID().toString()) : null, (simContextRep != null) ? (simContextRep.getName()) : null);
    return bioModelLink;
}
Also used : BioModelLink(cbit.vcell.server.BioModelLink) SimContextRep(cbit.vcell.modeldb.SimContextRep)

Example 3 with SimContextRep

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

the class RestDatabaseService method query.

public SimulationRepresentation query(BiomodelSimulationServerResource resource, User vcellUser) throws SQLException, DataAccessException, ExpressionException, XmlParseException, MappingException, MathException, MatrixException, ModelException {
    if (vcellUser == null) {
        vcellUser = VCellApiApplication.DUMMY_USER;
    }
    ArrayList<String> conditions = new ArrayList<String>();
    String bioModelID = (String) resource.getRequestAttributes().get(VCellApiApplication.BIOMODELID);
    if (bioModelID != null) {
        conditions.add("(" + BioModelTable.table.id.getQualifiedColName() + " = " + bioModelID + ")");
    } else {
        throw new RuntimeException(VCellApiApplication.BIOMODELID + " not specified");
    }
    StringBuffer conditionsBuffer = new StringBuffer();
    for (String condition : conditions) {
        if (conditionsBuffer.length() > 0) {
            conditionsBuffer.append(" AND ");
        }
        conditionsBuffer.append(condition);
    }
    int startRow = 1;
    int maxRows = 1;
    BioModelRep[] bioModelReps = databaseServerImpl.getBioModelReps(vcellUser, conditionsBuffer.toString(), null, 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);
            }
        }
    }
    if (bioModelReps == null || bioModelReps.length != 1) {
        // 
        // try to determine if the current credentials are insufficient, try to fetch BioModel again with administrator privilege.
        // 
        User adminUser = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
        BioModelRep[] allBioModelReps = databaseServerImpl.getBioModelReps(adminUser, conditionsBuffer.toString(), null, startRow, 1);
        if (allBioModelReps != null && allBioModelReps.length >= 0) {
            throw new PermissionException("insufficient privilege to retrive BioModel " + bioModelID);
        } else {
            throw new RuntimeException("failed to get biomodel");
        }
    }
    String simulationId = (String) resource.getRequestAttributes().get(VCellApiApplication.SIMULATIONID);
    if (simulationId == null) {
        throw new RuntimeException(VCellApiApplication.SIMULATIONID + " not specified");
    }
    SimulationRep simRep = getSimulationRep(new KeyValue(simulationId));
    BigString bioModelXML = databaseServerImpl.getBioModelXML(vcellUser, bioModelReps[0].getBmKey());
    BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
    return new SimulationRepresentation(simRep, bioModel);
}
Also used : PermissionException(org.vcell.util.PermissionException) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) ArrayList(java.util.ArrayList) BioModelRep(cbit.vcell.modeldb.BioModelRep) BigString(org.vcell.util.BigString) BigString(org.vcell.util.BigString) SimulationRepresentation(org.vcell.rest.common.SimulationRepresentation) BioModel(cbit.vcell.biomodel.BioModel) XMLSource(cbit.vcell.xml.XMLSource) SimContextRep(cbit.vcell.modeldb.SimContextRep) SimulationRep(cbit.vcell.modeldb.SimulationRep)

Example 4 with SimContextRep

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

the class RestDatabaseService method getSimContextRep.

public SimContextRep getSimContextRep(KeyValue key) throws DataAccessException, SQLException {
    SimContextRep simContextRep = scMap.get(key);
    if (simContextRep != null) {
        return simContextRep;
    } else {
        System.out.println("getting simulation context rep for scKey = " + key);
        simContextRep = databaseServerImpl.getSimContextRep(key);
        if (simContextRep != null) {
            System.out.println("found simulation context key = " + key + " number of cached simContexts is " + simMap.size());
            scMap.put(key, simContextRep);
        } else {
            System.out.println("couldn't find simulation key = " + key);
        }
        return simContextRep;
    }
}
Also used : SimContextRep(cbit.vcell.modeldb.SimContextRep)

Example 5 with SimContextRep

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

the class RestDatabaseService method getBioModelRep.

public BioModelRep getBioModelRep(KeyValue bmKey, User vcellUser) throws SQLException, ObjectNotFoundException, DataAccessException {
    if (vcellUser == null) {
        vcellUser = VCellApiApplication.DUMMY_USER;
    }
    ArrayList<String> conditions = new ArrayList<String>();
    if (bmKey != null) {
        conditions.add("(" + BioModelTable.table.id.getQualifiedColName() + " = " + bmKey.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);
    }
    int startRow = 1;
    int maxRows = 1;
    BioModelRep[] bioModelReps = databaseServerImpl.getBioModelReps(vcellUser, conditionsBuffer.toString(), null, 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);
            }
        }
    }
    if (bioModelReps == null || bioModelReps.length != 1) {
        throw new ObjectNotFoundException("failed to get biomodel");
    }
    return bioModelReps[0];
}
Also used : KeyValue(org.vcell.util.document.KeyValue) ArrayList(java.util.ArrayList) BioModelRep(cbit.vcell.modeldb.BioModelRep) BigString(org.vcell.util.BigString) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SimContextRep(cbit.vcell.modeldb.SimContextRep) SimulationRep(cbit.vcell.modeldb.SimulationRep)

Aggregations

SimContextRep (cbit.vcell.modeldb.SimContextRep)5 BioModelRep (cbit.vcell.modeldb.BioModelRep)3 SimulationRep (cbit.vcell.modeldb.SimulationRep)3 ArrayList (java.util.ArrayList)3 BigString (org.vcell.util.BigString)3 KeyValue (org.vcell.util.document.KeyValue)3 BioModel (cbit.vcell.biomodel.BioModel)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1 OrderBy (cbit.vcell.modeldb.DatabaseServerImpl.OrderBy)1 BioModelLink (cbit.vcell.server.BioModelLink)1 XMLSource (cbit.vcell.xml.XMLSource)1 Date (java.util.Date)1 SimulationRepresentation (org.vcell.rest.common.SimulationRepresentation)1 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)1 PermissionException (org.vcell.util.PermissionException)1 User (org.vcell.util.document.User)1