Search in sources :

Example 1 with Triplet

use of cern.laser.business.data.Triplet in project ACS by ACS-Community.

the class ACSAlarmDAOImpl method saveAllIDs.

private void saveAllIDs() {
    if (conf == null) {
        throw new IllegalStateException("null ConfigurationAccessor");
    }
    if (!conf.isWriteable()) {
        throw new RuntimeException("ConfigurationAccessor is not writeable");
    }
    StringBuffer result = new StringBuffer();
    result.append("<?xml version=\"1.0\"?>\n");
    result.append("<alarm-definition-list>\n");
    Iterator<Alarm> i = alarmDefs.values().iterator();
    while (i.hasNext()) {
        Alarm a = i.next();
        Triplet t = a.getTriplet();
        result.append("\t<alarm-definition fault-family=\"");
        DAOUtil.escapeXMLEntities(result, t.getFaultFamily());
        result.append("\" fault-member=\"");
        DAOUtil.escapeXMLEntities(result, t.getFaultMember());
        result.append("\" fault-code=\"");
        result.append(t.getFaultCode().intValue());
        result.append("\" />\n");
    }
    result.append("</alarm-definition-list>\n");
    try {
        conf.setConfiguration("/alarms", result.toString());
    } catch (Exception e) {
        throw new RuntimeException("Could not write alarm list", e);
    }
}
Also used : Triplet(cern.laser.business.data.Triplet) Alarm(cern.laser.business.data.Alarm) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) MalformedURLException(java.net.MalformedURLException)

Example 2 with Triplet

use of cern.laser.business.data.Triplet in project ACS by ACS-Community.

the class ACSAlarmDAOImpl method getAlarm.

/**
	 * Get an alarm from the cache.
	 * 
	 * Get an alarm from the cache. If the alarm with the given triplet is not in the cache then it
	 * looks for a default alarm before returning null.
	 * 
	 * If a default alarm is found, then a new alarm is created by cloning the default alarm.
	 * The triplet of this new alarm is set to be equal to the passed alarm ID.
	 * 
	 * @param alarmId The ID of the alarm
	 * @return An alarm with the given ID if it exists in the CDB
	 * 	       If an alarm with the give ID does not exist but a matching default alarm
	 *         is defined then it return a clone of the default alarm
	 *         null If the alarm is not defined in the CDB and a default alarm does not exist
	 *         
	 * 
	 */
public Alarm getAlarm(String alarmId) {
    if (conf == null) {
        throw new IllegalStateException("Missing dal");
    }
    if (alarmId == null) {
        throw new IllegalArgumentException("Invalid null alarm ID");
    }
    AlarmImpl alarm = (AlarmImpl) alarmDefs.get(alarmId);
    if (alarm == null) {
        // The alarm is not in the HashMap
        // 
        // Does it exist a default alarm?
        String[] tripletItems = alarmId.split(":");
        if (tripletItems.length != 3) {
            logger.log(AcsLogLevel.ERROR, "Malformed alarm ID: " + alarmId);
            return null;
        }
        // Build the default alarm ID by replacing the FM with DEFAULT_FM
        String defaultTripletID = tripletItems[0] + ":" + DEFAULT_FM + ":" + tripletItems[2];
        logger.log(AcsLogLevel.DEBUG, alarmId + " not found: looking for default alarm " + defaultTripletID);
        AlarmImpl defaultalarm = (AlarmImpl) alarmDefs.get(defaultTripletID);
        if (defaultalarm == null) {
            // No available default alarm for this triplet
            logger.log(AcsLogLevel.WARNING, "No default alarm found for " + alarmId);
            return null;
        }
        logger.log(AcsLogLevel.DEBUG, "Default alarm found for " + alarmId);
        System.out.println("Default alarm found for " + alarmId);
        alarm = (AlarmImpl) defaultalarm.clone();
        Triplet alarmTriplet = new Triplet(tripletItems[0], tripletItems[1], Integer.parseInt(tripletItems[2]));
        alarm.setTriplet(alarmTriplet);
        alarm.setAlarmId(Triplet.toIdentifier(alarmTriplet.getFaultFamily(), alarmTriplet.getFaultMember(), alarmTriplet.getFaultCode()));
        // Add the alarm in the HashMap
        //
        // addAlarmToCache trigger the sending of the alarm to the clients
        // i.e. a default alarm is sent to the client twice
        addAlarmToCache(alarm);
        // Refresh the reduction rules with the newly added alarm
        updateAlarmReductionRule(alarm);
        updateAlarmThreshold(alarm);
    //dumpReductionRules();
    }
    return alarm;
}
Also used : Triplet(cern.laser.business.data.Triplet) AlarmImpl(cern.laser.business.data.AlarmImpl)

Example 3 with Triplet

use of cern.laser.business.data.Triplet in project ACS by ACS-Community.

the class ReductionsView method createMRParentWidgets.

private void createMRParentWidgets() {
    _updateMRParentFF = new Listener() {

        public void handleEvent(Event event) {
            _MRParentFMCombo.removeAll();
            FaultMember[] fml = _alarmManager.getFaultFamily(_MRParentFFCombo.getText()).getFaultMember();
            for (int j = 0; j < fml.length; j++) {
                _MRParentFMCombo.add(fml[j].getName());
            }
            _MRParentFCCombo.removeAll();
            FaultCode[] fcl = _alarmManager.getFaultFamily(_MRParentFFCombo.getText()).getFaultCode();
            for (int j = 0; j < fcl.length; j++) {
                _MRParentFCCombo.add(String.valueOf(fcl[j].getValue()));
            }
            //_MRParentThresholdText.setText("");
            _MRParentErrorMessageLabel.setText("Please choose a Fault Member and a Fault Code.");
        }
    };
    _updateMRParent = new Listener() {

        public void handleEvent(Event event) {
            if (_tree.getSelection() == null || _tree.getSelection().length == 0)
                return;
            NodeType type = (NodeType) _tree.getSelection()[0].getData();
            if (type != NodeType.MULTIPLICITY_REDUCTION_PARENT_DATA)
                return;
            if (_MRParentFMCombo.getText().isEmpty()) {
                _MRParentErrorMessageLabel.setText("Please choose a Fault Member.");
                return;
            }
            if (_MRParentFCCombo.getText().isEmpty()) {
                _MRParentErrorMessageLabel.setText("Please choose a Fault Code.");
                return;
            }
            if (_MRParentThresholdText.getText().isEmpty()) {
                _MRParentErrorMessageLabel.setText("Please set a Threshold value.");
                return;
            }
            int thr;
            try {
                thr = Integer.parseInt(_MRParentThresholdText.getText());
            } catch (NumberFormatException e) {
                _MRParentErrorMessageLabel.setText("Incorrect Threshold. A number is required.");
                return;
            }
            String[] tr = getTriplet(_tree.getSelection()[0].getText());
            ReductionRule mrr = _reductionManager.getMRParentByTriplet(tr[0], tr[1], Integer.parseInt(tr[2]));
            ReductionRule mrr2 = _reductionManager.getMRParentByTriplet(_MRParentFFCombo.getText(), _MRParentFMCombo.getText(), Integer.parseInt(_MRParentFCCombo.getText()));
            Alarm parent = null;
            Alarm mParent;
            fillMRParentChAlarmList(_MRParentFFCombo.getText(), _MRParentFMCombo.getText(), Integer.parseInt(_MRParentFCCombo.getText()));
            if (mrr == null) {
                _MRParentErrorMessageLabel.setText("There's no Reduction Rule (no children) for the selected Alarm.");
                return;
            } else
                parent = mrr.getParent();
            if (mrr2 == null)
                mParent = _alarmManager.getAlarm(new String(_MRParentFFCombo.getText() + ":" + _MRParentFMCombo.getText() + ":" + _MRParentFCCombo.getText()));
            else {
                mParent = mrr2.getParent();
                if (mrr != mrr2) {
                    ErrorDialog edialog = new ErrorDialog(ReductionsView.this.getViewSite().getShell(), "Reduction Rule Already Exists", "The reduction rule you are trying to create already exists", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", "The reduction rule parent already exists"), IStatus.ERROR);
                    edialog.setBlockOnOpen(true);
                    edialog.open();
                    return;
                }
            }
            if (parent != null) {
                String[] ch = parent.getMultiplicityChildren();
                //Remove all Children from mrr and add them to mrr2.
                try {
                    for (int i = 0; i < ch.length; i++) {
                        Alarm aCh = _alarmManager.getAlarm(ch[i]);
                        if (aCh != null) {
                            if (!_reductionManager.deleteMultiReductionRule(parent, aCh)) {
                                _MRParentErrorMessageLabel.setText("One or more children alarms didn't exist.");
                                continue;
                            }
                            _reductionManager.addMultiReductionRule(mParent, aCh);
                        }
                    }
                    _reductionManager.updateMultiThreshold(mParent, thr);
                } catch (IllegalOperationException e) {
                    _MRParentErrorMessageLabel.setText("The parent alarm didn't exist.");
                }
                _tree.getSelection()[0].setText("<" + mParent.getAlarmId().replace(':', ',') + ">");
                _MRParentErrorMessageLabel.setText("");
            }
            if (mrr != null && mrr.getChildrenCount() < mrr.getThreshold()) {
                _MRParentErrorMessageLabel.setText("You need to have at least threshold (" + mrr.getThreshold() + ") childs for this triplet.");
                return;
            }
            if (tr[0].compareTo(_MRParentFFCombo.getText()) != 0 || tr[1].compareTo(_MRParentFMCombo.getText()) != 0 || tr[2].compareTo(_MRParentFCCombo.getText()) != 0) {
                sortReductionRulesList();
                Triplet t = mParent.getTriplet();
                selectElementFromTree("<" + t.getFaultFamily() + "," + t.getFaultMember() + "," + t.getFaultCode() + ">", false);
            }
        }
    };
    _updateMRParentChFF = new Listener() {

        public void handleEvent(Event event) {
            _MRParentChFMCombo.removeAll();
            _MRParentChFMCombo.add("Any");
            if (_MRParentChFFCombo.getText().compareTo("Any") != 0) {
                FaultMember[] fml = _alarmManager.getFaultFamily(_MRParentChFFCombo.getText()).getFaultMember();
                for (int j = 0; j < fml.length; j++) {
                    _MRParentChFMCombo.add(fml[j].getName());
                }
            }
            _MRParentChFMCombo.select(0);
            _MRParentChFCCombo.removeAll();
            _MRParentChFCCombo.add("Any");
            if (_MRParentChFFCombo.getText().compareTo("Any") != 0) {
                FaultCode[] fcl = _alarmManager.getFaultFamily(_MRParentChFFCombo.getText()).getFaultCode();
                for (int j = 0; j < fcl.length; j++) {
                    _MRParentChFCCombo.add(String.valueOf(fcl[j].getValue()));
                }
            }
            _MRParentChFCCombo.select(0);
            TreeItem[] tmp = _tree.getSelection();
            if (tmp == null || tmp.length == 0)
                return;
            TreeItem item = tmp[0];
            String[] triplet = getTriplet(item.getText());
            fillMRParentChAlarmList(triplet[0], triplet[1], Integer.parseInt(triplet[2]));
        }
    };
    _updateMRParentCh = new Listener() {

        public void handleEvent(Event event) {
            TreeItem[] tmp = _tree.getSelection();
            if (tmp == null || tmp.length == 0)
                return;
            TreeItem item = tmp[0];
            String[] triplet = getTriplet(item.getText());
            fillMRParentChAlarmList(triplet[0], triplet[1], Integer.parseInt(triplet[2]));
        }
    };
    _MRParentGroup = new Group(_compInitial, SWT.SHADOW_ETCHED_IN);
    GridLayout gl = new GridLayout();
    gl.numColumns = 1;
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    _MRParentGroup.setLayout(gl);
    _MRParentGroup.setLayoutData(gd);
    _MRParentFtGroup = new Group(_MRParentGroup, SWT.SHADOW_ETCHED_IN);
    gl = new GridLayout();
    gl.numColumns = 2;
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentFtGroup.setLayout(gl);
    _MRParentFtGroup.setLayoutData(gd);
    _MRParentFtGroup.setText("Primary Alarm");
    _MRParentFFLabel = new Label(_MRParentFtGroup, SWT.NONE);
    _MRParentFFLabel.setText("Fault Family:");
    _MRParentFFCombo = new Combo(_MRParentFtGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentFFCombo.setLayoutData(gd);
    _MRParentFFCombo.addListener(SWT.Selection, _updateMRParentFF);
    _MRParentFMLabel = new Label(_MRParentFtGroup, SWT.NONE);
    _MRParentFMLabel.setText("Fault Member:");
    _MRParentFMCombo = new Combo(_MRParentFtGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentFMCombo.setLayoutData(gd);
    _MRParentFMCombo.addListener(SWT.Selection, _updateMRParent);
    _MRParentFCLabel = new Label(_MRParentFtGroup, SWT.NONE);
    _MRParentFCLabel.setText("Fault Code:");
    _MRParentFCCombo = new Combo(_MRParentFtGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentFCCombo.setLayoutData(gd);
    _MRParentFCCombo.addListener(SWT.Selection, _updateMRParent);
    _MRParentThresholdLabel = new Label(_MRParentFtGroup, SWT.NONE);
    _MRParentThresholdLabel.setText("Threshold:");
    _MRParentThresholdText = new Text(_MRParentFtGroup, SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentThresholdText.setLayoutData(gd);
    _MRParentThresholdText.addListener(SWT.Modify, _updateMRParent);
    //
    _MRParentChGroup = new Group(_MRParentGroup, SWT.SHADOW_ETCHED_IN);
    gl = new GridLayout();
    gl.numColumns = 1;
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    _MRParentChGroup.setLayout(gl);
    _MRParentChGroup.setLayoutData(gd);
    _MRParentChGroup.setText("Alarms to Ignore");
    _MRParentChFilterGroup = new Group(_MRParentChGroup, SWT.SHADOW_ETCHED_IN);
    gl = new GridLayout();
    gl.numColumns = 2;
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentChFilterGroup.setLayout(gl);
    _MRParentChFilterGroup.setLayoutData(gd);
    _MRParentChFilterGroup.setText("Filter Options");
    _MRParentChFilterLevelGroup = new Group(_MRParentChFilterGroup, SWT.SHADOW_ETCHED_IN);
    gl = new GridLayout();
    gl.numColumns = 3;
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 2;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentChFilterLevelGroup.setLayout(gl);
    _MRParentChFilterLevelGroup.setLayoutData(gd);
    _MRParentChFilterLevelGroup.setText("Show");
    _MRParentChAllRadio = new Button(_MRParentChFilterLevelGroup, SWT.RADIO);
    _MRParentChAllRadio.setText("All");
    _MRParentChAllRadio.addListener(SWT.Selection, _updateMRParentCh);
    _MRParentChSelectedRadio = new Button(_MRParentChFilterLevelGroup, SWT.RADIO);
    _MRParentChSelectedRadio.setText("Selected");
    _MRParentChSelectedRadio.addListener(SWT.Selection, _updateMRParentCh);
    _MRParentChUnselectedRadio = new Button(_MRParentChFilterLevelGroup, SWT.RADIO);
    _MRParentChUnselectedRadio.setText("Unselected");
    _MRParentChUnselectedRadio.addListener(SWT.Selection, _updateMRParentCh);
    _MRParentChFFLabel = new Label(_MRParentChFilterGroup, SWT.NONE);
    _MRParentChFFLabel.setText("Fault Family:");
    _MRParentChFFCombo = new Combo(_MRParentChFilterGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentChFFCombo.setLayoutData(gd);
    _MRParentChFFCombo.addListener(SWT.Selection, _updateMRParentChFF);
    _MRParentChFMLabel = new Label(_MRParentChFilterGroup, SWT.NONE);
    _MRParentChFMLabel.setText("Fault Member:");
    _MRParentChFMCombo = new Combo(_MRParentChFilterGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentChFMCombo.setLayoutData(gd);
    _MRParentChFMCombo.addListener(SWT.Selection, _updateMRParentCh);
    _MRParentChFCLabel = new Label(_MRParentChFilterGroup, SWT.NONE);
    _MRParentChFCLabel.setText("Fault Code:");
    _MRParentChFCCombo = new Combo(_MRParentChFilterGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentChFCCombo.setLayoutData(gd);
    _MRParentChFCCombo.addListener(SWT.Selection, _updateMRParentCh);
    _MRParentChFilterLabel = new Label(_MRParentChFilterGroup, SWT.NONE);
    _MRParentChFilterLabel.setText("Filter RegEx:");
    _MRParentChFilterText = new Text(_MRParentChFilterGroup, SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _MRParentChFilterText.setLayoutData(gd);
    _MRParentChFilterText.addListener(SWT.Modify, _updateMRParentCh);
    _MRParentChAlarmList = new Table(_MRParentChGroup, SWT.BORDER);
    gd = new GridData();
    gd.verticalAlignment = SWT.FILL;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.grabExcessHorizontalSpace = true;
    _MRParentChAlarmList.setLayoutData(gd);
    _MRParentChAlarmList.addListener(SWT.KeyUp, _addRule);
    _MRParentChAlarmList.addListener(SWT.MouseDoubleClick, _addRule);
    _MRParentErrorMessageLabel = new Label(_MRParentGroup, SWT.NONE);
    _MRParentErrorMessageLabel.setText("");
    _MRParentErrorMessageLabel.setForeground(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    _MRParentErrorMessageLabel.setLayoutData(gd);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Group(org.eclipse.swt.widgets.Group) SelectionListener(org.eclipse.swt.events.SelectionListener) Listener(org.eclipse.swt.widgets.Listener) Table(org.eclipse.swt.widgets.Table) TreeItem(org.eclipse.swt.widgets.TreeItem) Triplet(cern.laser.business.data.Triplet) Label(org.eclipse.swt.widgets.Label) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) IllegalOperationException(cl.utfsm.acs.acg.core.IllegalOperationException) ReductionRule(cl.utfsm.acs.acg.core.ReductionRule) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) Alarm(cern.laser.business.data.Alarm) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 4 with Triplet

use of cern.laser.business.data.Triplet in project ACS by ACS-Community.

the class ReductionsView method sortMultiReductionRuleList.

public void sortMultiReductionRuleList(TreeItem iTree) {
    List<ReductionRule> rrList = _reductionManager.getMultiReductionRules();
    List<ReductionRule> sortedRRList = new ArrayList<ReductionRule>();
    List<String> tmp = new ArrayList<String>();
    for (ReductionRule rr : rrList) {
        Triplet t = rr.getParent().getTriplet();
        String name = "<" + t.getFaultFamily() + "," + t.getFaultMember() + "," + t.getFaultCode() + ">";
        tmp.add(name);
    }
    Collections.sort(tmp, IGNORE_CASE_ORDER);
    for (String srr : tmp) for (ReductionRule rr : rrList) {
        Triplet t = rr.getParent().getTriplet();
        String name = "<" + t.getFaultFamily() + "," + t.getFaultMember() + "," + t.getFaultCode() + ">";
        if (name.compareTo(srr) == 0)
            sortedRRList.add(rr);
    }
    rrList = sortedRRList;
    for (ReductionRule rule : rrList) {
        TreeItem kTree = new TreeItem(iTree, SWT.NONE);
        Triplet t = rule.getParent().getTriplet();
        kTree.setText("<" + t.getFaultFamily() + "," + t.getFaultMember() + "," + t.getFaultCode() + ">");
        kTree.setData(NodeType.MULTIPLICITY_REDUCTION_PARENT_DATA);
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) Triplet(cern.laser.business.data.Triplet) ArrayList(java.util.ArrayList) ReductionRule(cl.utfsm.acs.acg.core.ReductionRule)

Example 5 with Triplet

use of cern.laser.business.data.Triplet in project ACS by ACS-Community.

the class ACSAlarmDAOImpl method generateAlarmsMap.

/**
	 * Generate the alarms from the definition of the fault families.
	 * The alarms will be added into the HashMap with their triplet as key.
	 * The default item has FM="*".
	 * 
	 * The sources read from the families are also added to the HashMap of the sources
	 *  
	 * @param families The FF read from the CDB
	 */
private void generateAlarmsMap(Vector<FaultFamily> families) {
    if (families == null) {
        throw new IllegalArgumentException("Invalid null vector of FFs");
    }
    for (FaultFamily family : families) {
        String FF = family.getName();
        String helpUrl = family.getHelpUrl();
        String source = family.getAlarmSource();
        Contact contactPerson = family.getContact();
        FaultMember[] FMs = family.getFaultMember();
        FaultMemberDefault defaultFM = family.getFaultMemberDefault();
        FaultCode[] FCs = family.getFaultCode();
        // There should be at least one FC in the CDB
        if (FCs == null || FCs.length == 0) {
            logger.log(AcsLogLevel.WARNING, "No FC defined for family " + family.getName());
            continue;
        }
        // There should be at least one FM or a default FM defined in the CDB
        if (defaultFM == null && (FMs == null || FMs.length == 0)) {
            logger.log(AcsLogLevel.WARNING, "No FM defined for family " + family.getName());
            continue;
        }
        // Iterate over the FCs
        for (FaultCode code : FCs) {
            int FC = code.getValue();
            int priority = code.getPriority();
            String action = code.getAction();
            String cause = code.getCause();
            String consequence = code.getConsequence();
            String problemDesc = code.getProblemDescription();
            boolean instant = code.getInstant();
            // Iterate over all the FMs
            for (FaultMember member : FMs) {
                alma.acs.alarmsystem.generated.Location loc = member.getLocation();
                if (loc == null) {
                    loc = new alma.acs.alarmsystem.generated.Location();
                }
                if (loc.getBuilding() == null) {
                    loc.setBuilding("");
                }
                if (loc.getFloor() == null) {
                    loc.setFloor("");
                }
                if (loc.getMnemonic() == null) {
                    loc.setMnemonic("");
                }
                if (loc.getPosition() == null) {
                    loc.setPosition("");
                }
                if (loc.getRoom() == null) {
                    loc.setRoom("");
                }
                String FM = member.getName();
                if (FM.equals(DEFAULT_FM)) {
                    logger.log(AcsLogLevel.ERROR, "In the CDB, FM=" + DEFAULT_FM + " in family " + FF + " is not allowed");
                }
                AlarmImpl alarm = new AlarmImpl();
                alarm.setMultiplicityChildrenIds(new HashSet());
                alarm.setMultiplicityParentIds(new HashSet());
                alarm.setNodeChildrenIds(new HashSet());
                alarm.setNodeParentIds(new HashSet());
                alarm.setAction(action);
                alarm.setTriplet(new Triplet(FF, FM, FC));
                alarm.setCategories(new HashSet<Category>());
                alarm.setCause(cause);
                alarm.setConsequence(consequence);
                alarm.setProblemDescription(problemDesc);
                try {
                    alarm.setHelpURL(new URL(helpUrl));
                } catch (MalformedURLException e) {
                    alarm.setHelpURL(null);
                }
                alarm.setInstant(instant);
                Location location = new Location("0", loc.getFloor(), loc.getMnemonic(), loc.getPosition(), loc.getRoom());
                alarm.setLocation(location);
                if (contactPerson.getEmail() != null) {
                    alarm.setPiquetEmail(contactPerson.getEmail());
                } else {
                    alarm.setPiquetEmail("");
                }
                if (contactPerson.getGsm() != null) {
                    alarm.setPiquetGSM(contactPerson.getGsm());
                } else {
                    alarm.setPiquetGSM("");
                }
                alarm.setPriority(priority);
                ResponsiblePerson responsible = new ResponsiblePerson(0, contactPerson.getName(), "", contactPerson.getEmail(), contactPerson.getGsm(), "");
                alarm.setResponsiblePerson(responsible);
                SourceDefinition srcDef = new SourceDefinition(source, "SOURCE", "", 15, 1);
                Source src = new Source(srcDef, responsible);
                alarm.setSource(src);
                alarm.setIdentifier(alarm.getTriplet().toIdentifier());
                addAlarmToCache(alarm);
                if (!srcDefs.containsKey(source)) {
                    srcDefs.put(src.getSourceId(), src);
                    logger.log(AcsLogLevel.DEBUG, "Source " + src.getName() + " (id=" + src.getSourceId() + ") added");
                }
                logger.log(AcsLogLevel.DEBUG, "Alarm added " + alarm.getAlarmId());
            }
            // Add the default
            if (defaultFM != null) {
                alma.acs.alarmsystem.generated.Location loc = defaultFM.getLocation();
                if (loc == null) {
                    loc = new alma.acs.alarmsystem.generated.Location();
                }
                if (loc.getBuilding() == null) {
                    loc.setBuilding("");
                }
                if (loc.getFloor() == null) {
                    loc.setFloor("");
                }
                if (loc.getMnemonic() == null) {
                    loc.setMnemonic("");
                }
                if (loc.getPosition() == null) {
                    loc.setPosition("");
                }
                if (loc.getRoom() == null) {
                    loc.setRoom("");
                }
                AlarmImpl defaultAlarm = new AlarmImpl();
                defaultAlarm.setMultiplicityChildrenIds(new HashSet());
                defaultAlarm.setMultiplicityParentIds(new HashSet());
                defaultAlarm.setNodeChildrenIds(new HashSet());
                defaultAlarm.setNodeParentIds(new HashSet());
                defaultAlarm.setAction(action);
                defaultAlarm.setCategories(new HashSet<Category>());
                defaultAlarm.setCause(cause);
                defaultAlarm.setConsequence(consequence);
                defaultAlarm.setProblemDescription(problemDesc);
                try {
                    defaultAlarm.setHelpURL(new URL(helpUrl));
                } catch (MalformedURLException e) {
                    defaultAlarm.setHelpURL(null);
                }
                defaultAlarm.setInstant(instant);
                Location location = new Location("0", loc.getFloor(), loc.getMnemonic(), loc.getPosition(), loc.getRoom());
                defaultAlarm.setLocation(location);
                defaultAlarm.setPiquetEmail(contactPerson.getEmail());
                defaultAlarm.setPiquetGSM(contactPerson.getGsm());
                defaultAlarm.setPriority(priority);
                ResponsiblePerson responsible = new ResponsiblePerson(0, contactPerson.getName(), "", contactPerson.getEmail(), contactPerson.getGsm(), "");
                defaultAlarm.setResponsiblePerson(responsible);
                SourceDefinition srcDef = new SourceDefinition(source, "SOURCE", "", 15, 1);
                Source src = new Source(srcDef, responsible);
                defaultAlarm.setSource(src);
                defaultAlarm.setIdentifier(defaultAlarm.getTriplet().toIdentifier());
                Triplet triplet = new Triplet(FF, DEFAULT_FM, FC);
                defaultAlarm.setTriplet(triplet);
                defaultAlarm.setIdentifier(triplet.toIdentifier());
                addAlarmToCache(defaultAlarm);
                if (!srcDefs.containsKey(source)) {
                    srcDefs.put(src.getSourceId(), src);
                    logger.log(AcsLogLevel.DEBUG, "Source " + src.getName() + " (id=" + src.getSourceId() + ") added");
                }
                logger.log(AcsLogLevel.DEBUG, "Default alarm added " + defaultAlarm.getAlarmId());
            }
        }
    }
}
Also used : FaultCode(alma.acs.alarmsystem.generated.FaultCode) MalformedURLException(java.net.MalformedURLException) SourceDefinition(cern.laser.business.definition.data.SourceDefinition) Category(cern.laser.business.data.Category) URL(java.net.URL) Source(cern.laser.business.data.Source) InputSource(org.xml.sax.InputSource) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) HashSet(java.util.HashSet) FaultMember(alma.acs.alarmsystem.generated.FaultMember) Triplet(cern.laser.business.data.Triplet) Contact(alma.acs.alarmsystem.generated.Contact) FaultMemberDefault(alma.acs.alarmsystem.generated.FaultMemberDefault) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) AlarmImpl(cern.laser.business.data.AlarmImpl) Location(cern.laser.business.data.Location)

Aggregations

Triplet (cern.laser.business.data.Triplet)20 AlarmImpl (cern.laser.business.data.AlarmImpl)8 Alarm (cern.laser.business.data.Alarm)6 Location (cern.laser.business.data.Location)6 ResponsiblePerson (cern.laser.business.data.ResponsiblePerson)6 Source (cern.laser.business.data.Source)6 ReductionRule (cl.utfsm.acs.acg.core.ReductionRule)5 HashSet (java.util.HashSet)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 FaultCode (alma.acs.alarmsystem.generated.FaultCode)3 FaultFamily (alma.acs.alarmsystem.generated.FaultFamily)3 FaultMember (alma.acs.alarmsystem.generated.FaultMember)3 Building (cern.laser.business.data.Building)3 Category (cern.laser.business.data.Category)3 StatusImpl (cern.laser.business.data.StatusImpl)3 SourceDefinition (cern.laser.business.definition.data.SourceDefinition)3 IllegalOperationException (cl.utfsm.acs.acg.core.IllegalOperationException)3 MalformedURLException (java.net.MalformedURLException)3 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)3