Search in sources :

Example 1 with STRUC_TYPE

use of ambit2.base.interfaces.IStructureRecord.STRUC_TYPE in project ambit-mirror by ideaconsult.

the class AbstractFinder method process.

@Override
public IStructureRecord process(IStructureRecord target) throws AmbitException {
    try {
        if (target == null)
            return null;
        if ((AbstractFinder.MODE.emptyonly.equals(mode) || AbstractFinder.MODE.emptyadd.equals(mode)) && !STRUC_TYPE.NA.equals(target.getType()))
            return null;
        Iterator<Property> keys = profile.getProperties(true);
        Object value = null;
        while (keys.hasNext()) {
            Property key = keys.next();
            try {
                value = retrieveValue(target, key);
                if ((value == null) || "".equals(value.toString().trim()))
                    continue;
                RESULT content = query(value.toString());
                if (content != null) {
                    STRUC_TYPE originalType = target.getType();
                    target = transform(target, content);
                    switch(mode) {
                        case emptyonly:
                            {
                                if (!STRUC_TYPE.NA.equals(originalType)) {
                                    target.setIdstructure(-1);
                                }
                                break;
                            }
                        case emptyadd:
                            {
                                target.setIdstructure(-1);
                                target.setUsePreferedStructure(false);
                                break;
                            }
                        case replace:
                            {
                                target.setUsePreferedStructure(false);
                                break;
                            }
                        case propertyonly:
                            {
                                break;
                            }
                        default:
                            // add
                            target.setIdstructure(-1);
                            target.setUsePreferedStructure(false);
                            break;
                    }
                    return target;
                }
            } catch (HttpException x) {
                if (x.getCode() == 404)
                    logger.log(Level.WARNING, value == null ? x.getMessage() : value.toString(), x);
            } catch (Exception x) {
                logger.log(Level.SEVERE, value == null ? x.getMessage() : value.toString(), x);
            }
        }
    } catch (Exception x) {
        logger.log(Level.SEVERE, x.getMessage(), x);
    }
    return null;
}
Also used : STRUC_TYPE(ambit2.base.interfaces.IStructureRecord.STRUC_TYPE) HttpException(ambit2.base.exceptions.HttpException) Property(ambit2.base.data.Property) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) HttpException(ambit2.base.exceptions.HttpException)

Example 2 with STRUC_TYPE

use of ambit2.base.interfaces.IStructureRecord.STRUC_TYPE in project ambit-mirror by ideaconsult.

the class RetrieveStructure method getObject.

public IStructureRecord getObject(ResultSet rs) throws AmbitException {
    try {
        IStructureRecord r = getValue();
        r.clear();
        r.setIdchemical(rs.getInt(_sqlids.idchemical.name()));
        r.setIdstructure(rs.getInt(_sqlids.idstructure.name()));
        r.setContent(rs.getString(_sqlids.ustructure.name()));
        r.setFormat(rs.getString(_sqlids.format.name()));
        try {
            r.setSelected(rs.getBoolean("selected"));
        } catch (Exception x) {
            r.setSelected(true);
        }
        try {
            String t = rs.getString(_sqlids.type_structure.name());
            for (STRUC_TYPE type : STRUC_TYPE.values()) if (type.toString().equals(t)) {
                r.setType(type);
                break;
            }
        } catch (Exception x) {
            r.setType(STRUC_TYPE.NA);
        }
        try {
            Object ts = rs.getString(_sqlids.atomproperties.name());
            if ((ts == null) || "".equals(ts.toString().trim()))
                r.removeRecordProperty(Property.getInstance(CMLUtilities.SMARTSProp, CMLUtilities.SMARTSProp));
            else
                r.setRecordProperty(Property.getInstance(CMLUtilities.SMARTSProp, CMLUtilities.SMARTSProp), ts);
        } catch (Exception x) {
            r.removeRecordProperty(Property.getInstance(CMLUtilities.SMARTSProp, CMLUtilities.SMARTSProp));
        }
        return r;
    } catch (SQLException x) {
        throw new AmbitException(x);
    }
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) SQLException(java.sql.SQLException) STRUC_TYPE(ambit2.base.interfaces.IStructureRecord.STRUC_TYPE) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) SQLException(java.sql.SQLException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 3 with STRUC_TYPE

use of ambit2.base.interfaces.IStructureRecord.STRUC_TYPE in project ambit-mirror by ideaconsult.

the class RetrieveStructurePair method getObject.

protected void getObject(ResultSet rs, IStructureRecord r, int offset) throws SQLException {
    r.clear();
    r.setIdchemical(rs.getInt(rs_index.idchemical.ordinal() + offset));
    r.setIdstructure(rs.getInt(rs_index.idstructure.ordinal() + offset));
    r.setContent(rs.getString(rs_index.ustructure.ordinal() + offset));
    r.setFormat(rs.getString(rs_index.format.ordinal() + offset));
    try {
        String t = rs.getString(rs_index.type_structure.ordinal() + offset);
        for (STRUC_TYPE type : STRUC_TYPE.values()) if (type.toString().equals(t)) {
            r.setType(type);
            break;
        }
    } catch (Exception x) {
        r.setType(STRUC_TYPE.NA);
    }
    if ((rs.getString(rs_index.atomproperties.ordinal() + offset) == null) || "".equals(rs.getString(rs_index.atomproperties.ordinal() + offset).trim()))
        r.removeRecordProperty(Property.getInstance(CMLUtilities.SMARTSProp, CMLUtilities.SMARTSProp));
    else
        r.setRecordProperty(Property.getInstance(CMLUtilities.SMARTSProp, CMLUtilities.SMARTSProp), rs.getString(rs_index.atomproperties.ordinal() + offset));
}
Also used : STRUC_TYPE(ambit2.base.interfaces.IStructureRecord.STRUC_TYPE) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) SQLException(java.sql.SQLException)

Example 4 with STRUC_TYPE

use of ambit2.base.interfaces.IStructureRecord.STRUC_TYPE in project ambit-mirror by ideaconsult.

the class QueryStrucType method getParameters.

public List<QueryParam> getParameters() throws AmbitException {
    if (getValue() == null)
        throw new AmbitException("Structure type not defined");
    else {
        List<QueryParam> params = new ArrayList<QueryParam>();
        params.add(new QueryParam<Integer>(Integer.class, getId()));
        for (STRUC_TYPE st : getValue()) params.add(new QueryParam<String>(String.class, st.toString()));
        return params;
    }
}
Also used : QueryParam(net.idea.modbcum.i.query.QueryParam) STRUC_TYPE(ambit2.base.interfaces.IStructureRecord.STRUC_TYPE) ArrayList(java.util.ArrayList) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 5 with STRUC_TYPE

use of ambit2.base.interfaces.IStructureRecord.STRUC_TYPE in project ambit-mirror by ideaconsult.

the class QueryStrucType method getSQL.

public String getSQL() throws AmbitException {
    if (getValue() == null)
        throw new AmbitException("Structure type not defined");
    else {
        StringBuilder b = new StringBuilder();
        String or = "";
        for (STRUC_TYPE st : getValue()) {
            b.append(or);
            b.append(String.format(where, getCondition().getSQL()));
            or = " or ";
        }
        return String.format(sql, b.toString());
    }
}
Also used : STRUC_TYPE(ambit2.base.interfaces.IStructureRecord.STRUC_TYPE) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Aggregations

STRUC_TYPE (ambit2.base.interfaces.IStructureRecord.STRUC_TYPE)9 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)7 IStructureRecord (ambit2.base.interfaces.IStructureRecord)2 StringWriter (java.io.StringWriter)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)2 SDFWriter (org.openscience.cdk.io.SDFWriter)2 ResourceException (org.restlet.resource.ResourceException)2 Property (ambit2.base.data.Property)1 StructureRecord (ambit2.base.data.StructureRecord)1 HttpException (ambit2.base.exceptions.HttpException)1 Proportion (ambit2.base.relation.composition.Proportion)1 RetrieveStructure (ambit2.db.readers.RetrieveStructure)1 QueryExecutor (ambit2.db.search.QueryExecutor)1 MaterialAttributeValue (ambit2.export.isa.v1_0.objects.MaterialAttributeValue)1 ResultSet (java.sql.ResultSet)1 Point2d (javax.vecmath.Point2d)1 QueryParam (net.idea.modbcum.i.query.QueryParam)1 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)1