Search in sources :

Example 1 with AccessDeniedException

use of org.directwebremoting.extend.AccessDeniedException in project Gemma by PavlidisLab.

the class ExperimentalDesignControllerImpl method updateFactorValueCharacteristics.

@Override
public void updateFactorValueCharacteristics(FactorValueValueObject[] fvvos) {
    if (fvvos == null || fvvos.length == 0)
        return;
    for (FactorValueValueObject fvvo : fvvos) {
        Long fvID = fvvo.getId();
        if (fvID == null) {
            throw new IllegalArgumentException("Factor value id must be supplied");
        }
        FactorValue fv = this.factorValueService.load(fvID);
        if (fv == null) {
            throw new IllegalArgumentException("Could not load factorvalue with id=" + fvID);
        }
        if (!securityService.isEditable(fv)) {
            /*
                 * We do this instead of the interceptor because Characteristics are not securable, and we really don't
                 * want them to be.
                 */
            throw new AccessDeniedException("Access is denied");
        }
        // this is optional. Maybe we're actually adding a characteristic for the
        Long charId = fvvo.getCharId();
        // first time.
        Characteristic c;
        if (charId != null) {
            c = characteristicService.load(charId);
            if (c == null) {
                /*
                     * This shouldn't happen but just in case...
                     */
                throw new IllegalStateException("No characteristic with id " + fvvo.getCharId());
            }
            if (!fv.getCharacteristics().contains(c)) {
                throw new IllegalArgumentException("Characteristic with id=" + charId + " does not belong to factorvalue with id=" + fvID);
            }
        } else {
            if (StringUtils.isNotBlank(fvvo.getValueUri())) {
                c = VocabCharacteristic.Factory.newInstance();
            } else {
                c = Characteristic.Factory.newInstance();
            }
        }
        c.setCategory(fvvo.getCategory());
        c.setValue(fvvo.getValue());
        if (c instanceof VocabCharacteristic) {
            VocabCharacteristic vc = (VocabCharacteristic) c;
            vc.setCategoryUri(fvvo.getCategoryUri());
            vc.setValueUri(fvvo.getValueUri());
        }
        // characteristic has been manually updated
        c.setEvidenceCode(GOEvidenceCode.IC);
        if (c.getId() != null) {
            characteristicService.update(c);
        } else {
            fv.getCharacteristics().add(c);
            factorValueService.update(fv);
        }
    }
    FactorValue fv = this.factorValueService.load(fvvos[0].getId());
    ExpressionExperiment ee = expressionExperimentService.findByFactorValue(fv);
    // this.auditTrailService.addUpdateEvent( ee, ExperimentalDesignEvent.class,
    // "FactorValue characteristics updated", StringUtils.join( fvvos, "\n" ) );
    this.experimentReportService.evictFromCache(ee.getId());
}
Also used : AccessDeniedException(org.directwebremoting.extend.AccessDeniedException) Characteristic(ubic.gemma.model.common.description.Characteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic)

Aggregations

AccessDeniedException (org.directwebremoting.extend.AccessDeniedException)1 Characteristic (ubic.gemma.model.common.description.Characteristic)1 VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)1