Search in sources :

Example 1 with ValidationException

use of org.exolab.castor.xml.ValidationException in project OpenClinica by OpenClinica.

the class ImportRuleServlet method handleLoadCastor.

private RulesPostImportContainer handleLoadCastor(File xmlFile) {
    RulesPostImportContainer ruleImport = null;
    try {
        // create an XMLContext instance
        XMLContext xmlContext = new XMLContext();
        // create and set a Mapping instance
        Mapping mapping = xmlContext.createMapping();
        // mapping.loadMapping(SpringServletAccess.getPropertiesDir(context) + "mapping.xml");
        mapping.loadMapping(getCoreResources().getURL("mapping.xml"));
        xmlContext.addMapping(mapping);
        // create a new Unmarshaller
        Unmarshaller unmarshaller = xmlContext.createUnmarshaller();
        unmarshaller.setWhitespacePreserve(false);
        unmarshaller.setClass(RulesPostImportContainer.class);
        // Create a Reader to the file to unmarshal from
        FileReader reader = new FileReader(xmlFile);
        ruleImport = (RulesPostImportContainer) unmarshaller.unmarshal(reader);
        ruleImport.initializeRuleDef();
        logRuleImport(ruleImport);
        return ruleImport;
    } catch (FileNotFoundException ex) {
        throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
    } catch (IOException ex) {
        throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
    } catch (MarshalException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
    } catch (ValidationException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
    } catch (MappingException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
    }
}
Also used : RulesPostImportContainer(org.akaza.openclinica.domain.rule.RulesPostImportContainer) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) XMLContext(org.exolab.castor.xml.XMLContext) FileNotFoundException(java.io.FileNotFoundException) Mapping(org.exolab.castor.mapping.Mapping) FileReader(java.io.FileReader) IOException(java.io.IOException) Unmarshaller(org.exolab.castor.xml.Unmarshaller) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) MappingException(org.exolab.castor.mapping.MappingException)

Example 2 with ValidationException

use of org.exolab.castor.xml.ValidationException in project tdi-studio-se by Talend.

the class TMapSaveToEmfMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    IProxyRepositoryFactory factory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
    ProcessType processType = getProcessType(item);
    boolean modified = false;
    if (processType != null) {
        for (Object obj : processType.getNode()) {
            NodeType nodeType = (NodeType) obj;
            StringReader stringReader = null;
            if (nodeType.getStringData() != null && !"".equals(nodeType.getStringData())) {
                stringReader = new StringReader(nodeType.getStringData());
            }
            final String componentName = nodeType.getComponentName();
            if (stringReader != null) {
                if ("tMap".equals(componentName)) {
                    modified = true;
                    Unmarshaller unmarshaller = new Unmarshaller(ExternalMapperData.class);
                    unmarshaller.setWhitespacePreserve(true);
                    try {
                        ExternalMapperData externalData = (ExternalMapperData) unmarshaller.unmarshal(stringReader);
                        final MapperData emfMapperData = MapperFactory.eINSTANCE.createMapperData();
                        MapperHelper.saveDataToEmf(externalData, emfMapperData);
                        nodeType.setNodeData(emfMapperData);
                        nodeType.setStringData("");
                    } catch (MarshalException e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    } catch (ValidationException e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    } finally {
                        if (stringReader != null) {
                            stringReader.close();
                        }
                    }
                }
            }
        }
    }
    try {
        if (modified) {
            factory.save(item, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } else {
            return ExecutionResult.SUCCESS_NO_ALERT;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData) MapperData(org.talend.designer.mapper.model.emf.mapper.MapperData) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) StringReader(java.io.StringReader) Unmarshaller(org.exolab.castor.xml.Unmarshaller) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 3 with ValidationException

use of org.exolab.castor.xml.ValidationException in project ACS by ACS-Community.

the class ACSAlarmDAOImpl method getReductionRules.

public alma.alarmsystem.alarmmessage.generated.ReductionDefinitions getReductionRules() {
    if (conf == null)
        throw new IllegalStateException("null configuration accessor");
    alma.alarmsystem.alarmmessage.generated.ReductionDefinitions rds;
    String xml;
    try {
        xml = conf.getConfiguration(REDUCTION_DEFINITION_PATH);
    } catch (CDBRecordDoesNotExistEx e) {
        rds = new alma.alarmsystem.alarmmessage.generated.ReductionDefinitions();
        ReductionLinkDefinitionListType rld = new ReductionLinkDefinitionListType();
        rld.setReductionLink(new alma.alarmsystem.alarmmessage.generated.ReductionLinkType[0]);
        rds.setLinksToCreate(rld);
        alma.alarmsystem.alarmmessage.generated.Thresholds ths = new alma.alarmsystem.alarmmessage.generated.Thresholds();
        ths.setThreshold(new alma.alarmsystem.alarmmessage.generated.Threshold[0]);
        rds.setThresholds(ths);
        return rds;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    StringReader FFReader = new StringReader(xml);
    Unmarshaller FF_unmarshaller = new Unmarshaller(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions.class);
    FF_unmarshaller.setValidation(false);
    try {
        rds = (alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) FF_unmarshaller.unmarshal(FFReader);
    } catch (MarshalException e) {
        e.printStackTrace();
        return null;
    } catch (ValidationException e) {
        e.printStackTrace();
        return null;
    }
    try {
        rds.validate();
    } catch (ValidationException e) {
        e.printStackTrace();
    }
    return rds;
}
Also used : Thresholds(alma.alarmsystem.alarmmessage.generated.Thresholds) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) Thresholds(alma.alarmsystem.alarmmessage.generated.Thresholds) ReductionDefinitions(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) ReductionDefinitions(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) PatternSyntaxException(java.util.regex.PatternSyntaxException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx) ReductionLinkType(alma.alarmsystem.alarmmessage.generated.ReductionLinkType) StringReader(java.io.StringReader) Unmarshaller(org.exolab.castor.xml.Unmarshaller) ReductionLinkDefinitionListType(alma.alarmsystem.alarmmessage.generated.ReductionLinkDefinitionListType) Threshold(alma.alarmsystem.alarmmessage.generated.Threshold)

Example 4 with ValidationException

use of org.exolab.castor.xml.ValidationException in project ACS by ACS-Community.

the class ACSCategoryDAOImpl method getCategories.

public Categories getCategories() {
    if (conf == null || !conf.isWriteable())
        throw new IllegalStateException("no writable configuration accessor");
    Categories cats;
    String xml;
    try {
        xml = conf.getConfiguration(CATEGORY_DEFINITION_PATH);
    } catch (CDBRecordDoesNotExistEx e) {
        cats = new Categories();
        return cats;
    } catch (Exception e1) {
        e1.printStackTrace();
        return null;
    }
    StringReader FFReader = new StringReader(xml);
    Unmarshaller FF_unmarshaller = new Unmarshaller(Categories.class);
    FF_unmarshaller.setValidation(false);
    try {
        cats = (Categories) FF_unmarshaller.unmarshal(FFReader);
    } catch (MarshalException e1) {
        e1.printStackTrace();
        return null;
    } catch (ValidationException e1) {
        e1.printStackTrace();
        return null;
    }
    try {
        cats.validate();
    } catch (ValidationException e1) {
        e1.printStackTrace();
    }
    return cats;
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) Categories(alma.acs.alarmsystem.generated.Categories) StringReader(java.io.StringReader) Unmarshaller(org.exolab.castor.xml.Unmarshaller) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) IOException(java.io.IOException) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx)

Example 5 with ValidationException

use of org.exolab.castor.xml.ValidationException in project ACS by ACS-Community.

the class ReductionManager method saveToCDB.

public void saveToCDB() {
    Set<String> keyset = _objState.keySet();
    String[] objs = new String[keyset.size()];
    keyset.toArray(objs);
    ReductionDefinitions rds = ((ACSAlarmDAOImpl) _alarmDAO).getReductionRules();
    boolean flush = false;
    try {
        for (int i = 0; i < objs.length; i++) {
            ObjectState os = _objState.get(objs[i]);
            String[] spl = objs[i].split(",");
            String[] p = spl[0].split(":");
            String[] c = spl[1].split(":");
            ReductionLinkType rl = new ReductionLinkType();
            AlarmDefinition ad;
            Parent gp = new Parent();
            ad = new AlarmDefinition();
            ad.setFaultFamily(p[0]);
            ad.setFaultMember(p[1]);
            ad.setFaultCode(Integer.parseInt(p[2]));
            gp.setAlarmDefinition(ad);
            Child gc = new Child();
            ad = new AlarmDefinition();
            ad.setFaultFamily(c[0]);
            ad.setFaultMember(c[1]);
            ad.setFaultCode(Integer.parseInt(c[2]));
            gc.setAlarmDefinition(ad);
            rl.setParent(gp);
            rl.setChild(gc);
            if (spl[2].compareTo("n") == 0)
                rl.setType(ReductionLinkTypeTypeType.NODE);
            else
                rl.setType(ReductionLinkTypeTypeType.MULTIPLICITY);
            rl.validate();
            switch(os.getAction()) {
                case //Error, no state assigned.
                -1:
                    break;
                case 0:
                    break;
                case 1:
                    ((ACSAlarmDAOImpl) _alarmDAO).addReductionRule(rds, rl);
                    flush = true;
                    break;
                case 2:
                    ((ACSAlarmDAOImpl) _alarmDAO).updateReductionRule(rds, rl);
                    flush = true;
                    break;
                case 3:
                    ((ACSAlarmDAOImpl) _alarmDAO).deleteReductionRule(rds, rl);
                    flush = true;
                    break;
                default:
                    //Shouldn't happen.
                    break;
            }
        }
        keyset = _thrState.keySet();
        objs = new String[keyset.size()];
        keyset.toArray(objs);
        for (int i = 0; i < objs.length; i++) {
            AlarmDefinition al;
            String[] p = objs[i].split(":");
            al = new AlarmDefinition();
            al.setFaultFamily(p[0]);
            al.setFaultMember(p[1]);
            al.setFaultCode(Integer.parseInt(p[2]));
            ReductionRule rr = getMRParentByTriplet(p[0], p[1], Integer.parseInt(p[2]));
            Threshold th = new Threshold();
            th.setAlarmDefinition(al);
            if (rr == null)
                th.setValue(0);
            else
                th.setValue(rr.getThreshold());
            ObjectState ts = _thrState.get(objs[i]);
            th.validate();
            switch(ts.getAction()) {
                case //Error, no state assigned.
                -1:
                    break;
                case 0:
                    break;
                case 1:
                    ((ACSAlarmDAOImpl) _alarmDAO).addThreshold(rds, th);
                    flush = true;
                    break;
                case 2:
                    ((ACSAlarmDAOImpl) _alarmDAO).updateThreshold(rds, th);
                    flush = true;
                    break;
                case 3:
                    ((ACSAlarmDAOImpl) _alarmDAO).deleteThreshold(rds, th);
                    flush = true;
                    break;
                default:
                    //Shouldn't happen.
                    break;
            }
        }
        _objState.clear();
        _thrState.clear();
        if (flush)
            ((ACSAlarmDAOImpl) _alarmDAO).flushReductionRules(rds);
        for (ReductionRule rr : _nodeReductionRules) for (Alarm al : rr.getChildren()) if (rr.getIsNodeReduction())
            _objState.put(new String(rr.getParent().getAlarmId() + "," + al.getAlarmId() + ",n"), new ObjectState(false));
        for (ReductionRule rr : _multiReductionRules) {
            for (Alarm al : rr.getChildren()) if (!rr.getIsNodeReduction())
                _objState.put(new String(rr.getParent().getAlarmId() + "," + al.getAlarmId() + ",m"), new ObjectState(false));
            _thrState.put(rr.getParent().getAlarmId(), new ObjectState(false));
        }
    } catch (ValidationException e) {
        e.printStackTrace();
    }
}
Also used : ValidationException(org.exolab.castor.xml.ValidationException) Parent(alma.alarmsystem.alarmmessage.generated.Parent) AlarmDefinition(alma.alarmsystem.alarmmessage.generated.AlarmDefinition) ReductionDefinitions(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) ReductionLinkType(alma.alarmsystem.alarmmessage.generated.ReductionLinkType) Alarm(cern.laser.business.data.Alarm) ACSAlarmDAOImpl(cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl) Child(alma.alarmsystem.alarmmessage.generated.Child) Threshold(alma.alarmsystem.alarmmessage.generated.Threshold)

Aggregations

ValidationException (org.exolab.castor.xml.ValidationException)19 MarshalException (org.exolab.castor.xml.MarshalException)16 IOException (java.io.IOException)15 StringWriter (java.io.StringWriter)7 Marshaller (org.exolab.castor.xml.Marshaller)7 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)6 StringReader (java.io.StringReader)6 Unmarshaller (org.exolab.castor.xml.Unmarshaller)6 CDBRecordDoesNotExistEx (alma.cdbErrType.CDBRecordDoesNotExistEx)5 FileNotFoundException (java.io.FileNotFoundException)4 MalformedURLException (java.net.MalformedURLException)4 PatternSyntaxException (java.util.regex.PatternSyntaxException)4 FaultFamily (alma.acs.alarmsystem.generated.FaultFamily)3 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)3 Mapping (org.exolab.castor.mapping.Mapping)3 MappingException (org.exolab.castor.mapping.MappingException)3 XMLContext (org.exolab.castor.xml.XMLContext)3 Categories (alma.acs.alarmsystem.generated.Categories)2 ReductionDefinitions (alma.alarmsystem.alarmmessage.generated.ReductionDefinitions)2 ReductionLinkType (alma.alarmsystem.alarmmessage.generated.ReductionLinkType)2