Search in sources :

Example 1 with ObjectFilter

use of ubic.gemma.persistence.util.ObjectFilter in project Gemma by PavlidisLab.

the class FilterArg method getObjectFilters.

/**
 * Creates an ArrayList of Object Filter arrays, that can be used as a filter parameter for service value object
 * retrieval.
 *
 * @return an ArrayList of Object Filter arrays, each array represents a disjunction (OR) of filters. Arrays
 * then represent a conjunction (AND) with other arrays in the list.
 */
public ArrayList<ObjectFilter[]> getObjectFilters() {
    this.checkMalformed();
    if (propertyNames == null || propertyNames.isEmpty())
        return null;
    ArrayList<ObjectFilter[]> filterList = new ArrayList<>(propertyNames.size());
    for (int i = 0; i < propertyNames.size(); i++) {
        try {
            String[] properties = propertyNames.get(i);
            String[] values = propertyValues.get(i);
            String[] operators = propertyOperators.get(i);
            Class[] types = propertyTypes.get(i);
            ObjectFilter[] filterArray = new ObjectFilter[properties.length];
            for (int j = 0; j < properties.length; j++) {
                filterArray[j] = new ObjectFilter(properties[j], types[j], values[j], operators[j], objectAlias);
            }
            filterList.add(filterArray);
        } catch (IndexOutOfBoundsException e) {
            throw new GemmaApiException(new WellComposedErrorBody(Response.Status.BAD_REQUEST, ERROR_MSG_ARGS_MISALIGNED));
        } catch (ParseException e) {
            WellComposedErrorBody error = new WellComposedErrorBody(Response.Status.BAD_REQUEST, ERROR_MSG_MALFORMED_REQUEST);
            WellComposedErrorBody.addExceptionFields(error, e);
            throw new GemmaApiException(error);
        }
    }
    return filterList;
}
Also used : ArrayList(java.util.ArrayList) WellComposedErrorBody(ubic.gemma.web.services.rest.util.WellComposedErrorBody) ObjectFilter(ubic.gemma.persistence.util.ObjectFilter) GemmaApiException(ubic.gemma.web.services.rest.util.GemmaApiException) ParseException(java.text.ParseException)

Example 2 with ObjectFilter

use of ubic.gemma.persistence.util.ObjectFilter in project Gemma by PavlidisLab.

the class PlatformArg method getExperiments.

/**
 * Retrieves the Datasets of the Platform that this argument represents.
 *
 * @param service   service that will be used to retrieve the persistent AD object.
 * @param eeService service to use to retrieve the EEs.
 * @return a collection of Datasets that the platform represented by this argument contains.
 */
public Collection<ExpressionExperimentValueObject> getExperiments(ArrayDesignService service, ExpressionExperimentService eeService, int limit, int offset) {
    ArrayDesign ad = this.getPersistentObject(service);
    ArrayList<ObjectFilter[]> filters = new ArrayList<>(1);
    filters.add(new ObjectFilter[] { new ObjectFilter("id", ad.getId(), ObjectFilter.is, ObjectFilter.DAO_AD_ALIAS) });
    return eeService.loadValueObjectsPreFilter(offset, limit, "id", true, filters);
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ArrayList(java.util.ArrayList) ObjectFilter(ubic.gemma.persistence.util.ObjectFilter)

Example 3 with ObjectFilter

use of ubic.gemma.persistence.util.ObjectFilter in project Gemma by PavlidisLab.

the class ArrayEntityArg method combineFilters.

/**
 * Combines the given filters with the properties in this array to create a final filter to be used for VO retrieval.
 * Note that this does not check whether objects with identifiers in this array arg do actually exist. This merely creates
 * a set of filters that should be used to impose restrictions in the database query.
 * You can call this#getPersistentObjects which does try to retrieve the corresponding objects, and consequently
 * does yield a 404 error if an object for any of the identifiers in this array arg does not exist.
 *
 * @param service the service used to guess the type and name of the property that this arrayEntityArg represents.
 * @param filters the filters list to add the new filter to. Can be null.
 * @return the same array list as given, with a new added element, or a new ArrayList, in case the given filters
 * was null.
 */
public ArrayList<ObjectFilter[]> combineFilters(ArrayList<ObjectFilter[]> filters, S service) {
    if (filters == null) {
        filters = new ArrayList<>();
    }
    String name = this.getPropertyName(service);
    Class<?> type = String.class;
    if (name.equals("id")) {
        type = Long.class;
    }
    ObjectFilter filter;
    try {
        filter = new ObjectFilter(name, type, this.getValue(), ObjectFilter.in, this.getObjectDaoAlias());
    } catch (ParseException e) {
        throw this.convertParseException(e);
    }
    filters.add(new ObjectFilter[] { filter });
    return filters;
}
Also used : ObjectFilter(ubic.gemma.persistence.util.ObjectFilter) ParseException(java.text.ParseException)

Example 4 with ObjectFilter

use of ubic.gemma.persistence.util.ObjectFilter in project Gemma by PavlidisLab.

the class ArrayDesignDaoImpl method loadValueObjectsByIds.

@Override
public Collection<ArrayDesignValueObject> loadValueObjectsByIds(Collection<Long> ids) {
    if (ids == null) {
        return new ArrayList<>();
    }
    Map<Long, Integer> eeCounts = this.getExpressionExperimentCountMap(ids);
    ObjectFilter filter = new ObjectFilter("id", ids, ObjectFilter.in, ObjectFilter.DAO_AD_ALIAS);
    Query queryObject = this.getLoadValueObjectsQueryString(ObjectFilter.singleFilter(filter), null, false);
    return this.processADValueObjectQueryResults(eeCounts, queryObject);
}
Also used : ObjectFilter(ubic.gemma.persistence.util.ObjectFilter)

Example 5 with ObjectFilter

use of ubic.gemma.persistence.util.ObjectFilter in project Gemma by PavlidisLab.

the class ArrayDesignDaoImpl method getLoadValueObjectsQueryString.

private Query getLoadValueObjectsQueryString(ArrayList<ObjectFilter[]> filters, String orderByProperty, boolean orderDesc) {
    // Restrict to non-troubled EEs for non-administrators
    if (!SecurityUtil.isUserAdmin()) {
        if (filters == null) {
            filters = new ArrayList<>(ArrayDesignDaoImpl.NON_ADMIN_QUERY_FILTER_COUNT);
        } else {
            filters.ensureCapacity(filters.size() + ArrayDesignDaoImpl.NON_ADMIN_QUERY_FILTER_COUNT);
        }
        filters.add(new ObjectFilter[] { new ObjectFilter("curationDetails.troubled", false, ObjectFilter.is, ObjectFilter.DAO_AD_ALIAS) });
    }
    String queryString = // 0
    "select " + ObjectFilter.DAO_AD_ALIAS + ".id, " + ObjectFilter.DAO_AD_ALIAS + // 1
    ".name, " + ObjectFilter.DAO_AD_ALIAS + // 2
    ".shortName, " + ObjectFilter.DAO_AD_ALIAS + // 3
    ".technologyType, " + ObjectFilter.DAO_AD_ALIAS + // 4
    ".description, " + // 5
    "m, " + // 6
    "s.lastUpdated, " + // 7
    "s.troubled, " + // 8
    "s.needsAttention, " + // 9
    "s.curationNote, " + // 10
    "t.commonName, " + // 11
    "eNote, " + // 12
    "eAttn, " + // 13
    "eTrbl " + "from ArrayDesign as " + ObjectFilter.DAO_AD_ALIAS + " join " + ObjectFilter.DAO_AD_ALIAS + ".curationDetails s join " + ObjectFilter.DAO_AD_ALIAS + ".primaryTaxon t left join " + ObjectFilter.DAO_AD_ALIAS + ".mergedInto m left join s.lastNeedsAttentionEvent as eAttn " + "left join s.lastNoteUpdateEvent as eNote left join s.lastTroubledEvent as eTrbl ";
    queryString += AbstractVoEnabledDao.formAclSelectClause(ObjectFilter.DAO_AD_ALIAS, "ubic.gemma.model.expression.arrayDesign.ArrayDesign");
    queryString += AbstractVoEnabledDao.formRestrictionClause(filters);
    queryString += "group by " + ObjectFilter.DAO_AD_ALIAS + ".id ";
    queryString += AbstractVoEnabledDao.formOrderByProperty(orderByProperty, orderDesc);
    Query query = this.getSessionFactory().getCurrentSession().createQuery(queryString);
    AbstractVoEnabledDao.addRestrictionParameters(query, filters);
    return query;
}
Also used : ObjectFilter(ubic.gemma.persistence.util.ObjectFilter)

Aggregations

ObjectFilter (ubic.gemma.persistence.util.ObjectFilter)6 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)1 GemmaApiException (ubic.gemma.web.services.rest.util.GemmaApiException)1 WellComposedErrorBody (ubic.gemma.web.services.rest.util.WellComposedErrorBody)1