Search in sources :

Example 1 with Contact

use of alma.acs.alarmsystem.generated.Contact in project ACS by ACS-Community.

the class AlarmsView method createFFWidgets.

private void createFFWidgets() {
    _updateFaultFamily = new Listener() {

        public void handleEvent(Event event) {
            TreeItem tmp = _tree.getSelection()[0];
            String ff = tmp.getText();
            FaultFamily fft = new FaultFamily();
            //TODO: Error icon or something similar
            if (_ffNameText.getText().isEmpty()) {
                _ffErrorMessageLabel.setText("FaultFamily Name Missing!");
                return;
            }
            if (_ffNameText.getText().contains(" ")) {
                _ffErrorMessageLabel.setText("Invalid FaultFamily Name. No spaces allowed.");
                return;
            }
            fft.setName(_ffNameText.getText());
            if (!_ffHelpURLText.getText().isEmpty()) {
                URI hurl;
                try {
                    hurl = new URI(_ffHelpURLText.getText());
                } catch (MalformedURIException e1) {
                    _ffErrorMessageLabel.setText("Malformed URL!");
                    return;
                }
                fft.setHelpUrl(hurl.toString());
            }
            fft.setAlarmSource(_ffSourceCombo.getText());
            Contact ct = new Contact();
            if (_ffContactNameText.getText().isEmpty()) {
                _ffErrorMessageLabel.setText("Contact Name Missing!");
                return;
            }
            ct.setName(_ffContactNameText.getText());
            if (!_ffContactMailText.getText().isEmpty())
                ct.setEmail(_ffContactMailText.getText());
            if (!_ffContactGSMText.getText().isEmpty())
                ct.setGsm(_ffContactGSMText.getText());
            fft.setContact(ct);
            _ffErrorMessageLabel.setText("");
            try {
                _alarmManager.updateFaultFamily(_alarmManager.getFaultFamily(ff), fft);
                tmp.setText(_ffNameText.getText());
                IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
                IViewReference[] views = _window.getActivePage().getViewReferences();
                IMyViewPart view = ((IMyViewPart) views[2].getView(false));
                view.fillWidgets();
                if (ff.compareTo(fft.getName()) != 0) {
                    sortFaultFamilyList();
                    selectElementFromTree(fft.getName(), null, null);
                }
            } catch (IllegalOperationException e) {
                _ffErrorMessageLabel.setText(e.getMessage());
            } catch (NullPointerException e) {
                e.printStackTrace();
                _ffErrorMessageLabel.setText(e.getMessage());
            }
        }
    };
    _addCategory = new Listener() {

        public void handleEvent(Event event) {
            if (event.type == SWT.KeyUp)
                if (!(event.keyCode == SWT.CR || event.keyCode == ' '))
                    return;
            if (event.type == SWT.MouseDoubleClick) {
                Point pt = new Point(event.x, event.y);
                if (_ffCategoryList.getItem(pt) == null)
                    return;
            }
            TreeItem[] tmp1 = _tree.getSelection();
            if (tmp1 == null || tmp1.length == 0)
                return;
            String ff = tmp1[0].getText();
            TableItem[] tmp2 = _ffCategoryList.getSelection();
            if (tmp2 == null || tmp2.length == 0)
                return;
            TableItem item = tmp2[0];
            Category c = _categoryManager.getCategoryByPath(item.getText());
            try {
                String[] ffs = c.getAlarms().getFaultFamily();
                for (int i = 0; i < ffs.length; i++) {
                    if (ff.compareTo(ffs[i]) == 0) {
                        c.getAlarms().removeFaultFamily(ff);
                        item.setImage((org.eclipse.swt.graphics.Image) null);
                        IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
                        IViewReference[] views = _window.getActivePage().getViewReferences();
                        IMyViewPart view = ((IMyViewPart) views[2].getView(false));
                        view.fillWidgets();
                        return;
                    }
                }
                c.getAlarms().addFaultFamily(ff);
                item.setImage(Activator.getDefault().getImageRegistry().get(Activator.IMG_TICKET));
            } catch (NullPointerException e) {
                item.setImage((org.eclipse.swt.graphics.Image) null);
                Alarms alarms = new Alarms();
                alarms.addFaultFamily(ff.toString());
                alarms.setFaultFamily(0, ff.toString());
                c.setAlarms(alarms);
                item.setImage(Activator.getDefault().getImageRegistry().get(Activator.IMG_TICKET));
            }
            IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
            IViewReference[] views = _window.getActivePage().getViewReferences();
            IMyViewPart view = ((IMyViewPart) views[2].getView(false));
            view.fillWidgets();
        }
    };
    _FFgroup = new Group(_compInitial, SWT.SHADOW_ETCHED_IN);
    _FFgroup.setText("Fault Family details");
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    _FFgroup.setLayoutData(gd);
    GridLayout gl = new GridLayout();
    gl.numColumns = 2;
    _FFgroup.setLayout(gl);
    _ffNameLabel = new Label(_FFgroup, SWT.NONE);
    _ffNameLabel.setText("Fault Family name");
    _ffNameText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffNameText.setLayoutData(gd);
    _ffNameText.addListener(SWT.Modify, _updateFaultFamily);
    _ffHelpURLLabel = new Label(_FFgroup, SWT.NONE);
    _ffHelpURLLabel.setText("Help URL");
    _ffHelpURLText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffHelpURLText.setLayoutData(gd);
    _ffHelpURLText.addListener(SWT.Modify, _updateFaultFamily);
    _ffContactNameLabel = new Label(_FFgroup, SWT.NONE);
    _ffContactNameLabel.setText("Contact name");
    _ffContactNameText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffContactNameText.setLayoutData(gd);
    _ffContactNameText.addListener(SWT.Modify, _updateFaultFamily);
    _ffContactMailLabel = new Label(_FFgroup, SWT.NONE);
    _ffContactMailLabel.setText("Contact e-mail");
    _ffContactMailText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffContactMailText.setLayoutData(gd);
    _ffContactMailText.addListener(SWT.Modify, _updateFaultFamily);
    _ffContactGSMLabel = new Label(_FFgroup, SWT.NONE);
    _ffContactGSMLabel.setText("Contact GSM");
    _ffContactGSMText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffContactGSMText.setLayoutData(gd);
    _ffContactGSMText.addListener(SWT.Modify, _updateFaultFamily);
    _ffSourceLabel = new Label(_FFgroup, SWT.NONE);
    _ffSourceLabel.setText("Source");
    _ffSourceCombo = new Combo(_FFgroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffSourceCombo.setLayoutData(gd);
    _ffSourceCombo.setEnabled(false);
    _ffSourceCombo.addListener(SWT.Modify, _updateFaultFamily);
    _ffCategoryLabel = new Label(_FFgroup, SWT.NONE);
    _ffCategoryLabel.setText("Categories:");
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    _ffCategoryLabel.setLayoutData(gd);
    _ffCategoryList = new Table(_FFgroup, SWT.BORDER);
    gd = new GridData();
    gd.verticalAlignment = SWT.FILL;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 2;
    _ffCategoryList.setLayoutData(gd);
    _ffCategoryList.addListener(SWT.KeyUp, _addCategory);
    _ffCategoryList.addListener(SWT.MouseDoubleClick, _addCategory);
    Menu categoryPopUp = new Menu(_ffCategoryList);
    _ffCategoryList.setMenu(categoryPopUp);
    categoryPopUp.addListener(SWT.Show, new Listener() {

        public void handleEvent(Event e) {
            TableItem[] sel = _ffCategoryList.getSelection();
            Menu categoryPopUp = _ffCategoryList.getMenu();
            MenuItem[] items = categoryPopUp.getItems();
            for (int i = 0; i < items.length; i++) items[i].dispose();
            if (sel == null || sel.length == 0)
                return;
            MenuItem mitem;
            mitem = new MenuItem(categoryPopUp, SWT.PUSH);
            if (sel[0].getImage() == null) {
                mitem.setText("Add to Category");
                mitem.addListener(SWT.Selection, _addCategory);
            } else {
                mitem.setText("Remove from Category");
                mitem.addListener(SWT.Selection, _addCategory);
            }
        }
    });
    _ffErrorMessageLabel = new Label(_FFgroup, SWT.NONE);
    _ffErrorMessageLabel.setText("");
    _ffErrorMessageLabel.setForeground(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    _ffErrorMessageLabel.setLayoutData(gd);
}
Also used : Group(org.eclipse.swt.widgets.Group) SelectionListener(org.eclipse.swt.events.SelectionListener) Listener(org.eclipse.swt.widgets.Listener) MalformedURIException(org.apache.xerces.util.URI.MalformedURIException) Category(alma.acs.alarmsystem.generated.Category) TreeItem(org.eclipse.swt.widgets.TreeItem) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) URI(org.apache.xerces.util.URI) GridLayout(org.eclipse.swt.layout.GridLayout) Menu(org.eclipse.swt.widgets.Menu) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Table(org.eclipse.swt.widgets.Table) Alarms(alma.acs.alarmsystem.generated.Alarms) Text(org.eclipse.swt.widgets.Text) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) IllegalOperationException(cl.utfsm.acs.acg.core.IllegalOperationException) Contact(alma.acs.alarmsystem.generated.Contact) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 2 with Contact

use of alma.acs.alarmsystem.generated.Contact 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)

Example 3 with Contact

use of alma.acs.alarmsystem.generated.Contact 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
	 */
public 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());
                alarmDefs.put(alarm.getAlarmId(), 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());
                alarmDefs.put(defaultAlarm.getAlarmId(), 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)

Example 4 with Contact

use of alma.acs.alarmsystem.generated.Contact in project ACS by ACS-Community.

the class ACSAlarmDAOImplTest method testAddFaultFamily.

public void testAddFaultFamily() {
    boolean exception;
    Alarm al1;
    cern.laser.business.data.Location l;
    //Delete Entry if it exists due to an error in previous test
    {
        FaultFamily ff = new FaultFamily();
        ff.setName("ffTest1");
        try {
            _alarmDAO.removeFaultFamily(ff);
        } catch (Exception e) {
        //This happens when FaultFamily "ffTest1" doesn't exist
        }
    }
    //Check Null Argument
    exception = false;
    try {
        _alarmDAO.addFaultFamily(null);
    } catch (Exception e) {
        exception = true;
    }
    assertTrue(exception);
    //Check new FaultFamily
    FaultFamily ff = new FaultFamily();
    ff.setName("ffTest1");
    ff.setAlarmSource("ALARM_SYSTEM_SOURCES");
    ff.setHelpUrl("http://www.test.com");
    Contact ct = new Contact();
    ct.setEmail("em1");
    ct.setGsm("gsm1");
    ct.setName("cont1");
    ff.setContact(ct);
    FaultCode fc = new FaultCode();
    fc.setValue(1);
    fc.setPriority(0);
    fc.setAction("action1");
    fc.setCause("cause1");
    fc.setConsequence("conseq1");
    fc.setProblemDescription("problem1");
    ff.addFaultCode(fc);
    FaultMemberDefault fmd = new FaultMemberDefault();
    Location lc = new Location();
    lc.setBuilding("b1");
    lc.setFloor("f1");
    lc.setMnemonic("m1");
    lc.setPosition("p1");
    lc.setRoom("r1");
    fmd.setLocation(lc);
    ff.setFaultMemberDefault(fmd);
    FaultMember fm = new FaultMember();
    fm.setName("fmTest1");
    lc = new Location();
    lc.setBuilding("b2");
    lc.setFloor("f2");
    lc.setMnemonic("m2");
    lc.setPosition("p2");
    lc.setRoom("r2");
    fm.setLocation(lc);
    ff.addFaultMember(fm);
    exception = false;
    try {
        _alarmDAO.addFaultFamily(ff);
    } catch (Exception e) {
        exception = true;
    }
    assertFalse(exception);
    al1 = _alarmDAO.getAlarm("ffTest1:fmTest1:1");
    assertNotNull(al1);
    assertEquals("ALARM_SYSTEM_SOURCES", al1.getSource().getName());
    assertEquals("http://www.test.com", al1.getHelpURL().toString());
    assertEquals("em1", al1.getPiquetEmail());
    assertEquals("gsm1", al1.getPiquetGSM());
    assertEquals("cont1", al1.getResponsiblePerson().getFamilyName());
    assertEquals(0, al1.getPriority().intValue());
    assertEquals("action1", al1.getAction());
    assertEquals("cause1", al1.getCause());
    assertEquals("conseq1", al1.getConsequence());
    assertEquals("problem1", al1.getProblemDescription());
    l = al1.getLocation();
    assertNotNull(l);
    //assertEquals("b2",l.getBuilding()); //Null
    assertEquals("f2", l.getFloor());
    assertEquals("m2", l.getMnemonic());
    assertEquals("p2", l.getPosition());
    assertEquals("r2", l.getRoom());
    //Check if it already exists
    exception = false;
    try {
        _alarmDAO.addFaultFamily(ff);
    } catch (Exception e) {
        exception = true;
    }
    assertTrue(exception);
}
Also used : FaultCode(alma.acs.alarmsystem.generated.FaultCode) FaultMember(alma.acs.alarmsystem.generated.FaultMember) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) Alarm(cern.laser.business.data.Alarm) Contact(alma.acs.alarmsystem.generated.Contact) FaultMemberDefault(alma.acs.alarmsystem.generated.FaultMemberDefault) Location(alma.acs.alarmsystem.generated.Location)

Example 5 with Contact

use of alma.acs.alarmsystem.generated.Contact in project ACS by ACS-Community.

the class ACSAlarmDAOImplTest method testUpdateFaultFamily.

public void testUpdateFaultFamily() {
    boolean exception;
    Alarm al1;
    cern.laser.business.data.Location l;
    //Delete Entry if it exists due to an error in previous test
    {
        FaultFamily ff = new FaultFamily();
        ff.setName("ffTest1");
        try {
            _alarmDAO.removeFaultFamily(ff);
        } catch (Exception e) {
        //This happens when FaultFamily "ffTest1" doesn't exist
        }
    }
    //Check Null Argument
    exception = false;
    try {
        _alarmDAO.updateFaultFamily(null);
    } catch (Exception e) {
        exception = true;
    }
    assertTrue(exception);
    //Update a FaultFamily that doesn't exist
    FaultFamily ff = new FaultFamily();
    ff.setName("ffTest1");
    exception = false;
    try {
        _alarmDAO.updateFaultFamily(ff);
    } catch (Exception e) {
        exception = true;
    }
    assertTrue(exception);
    //Check updating FaultFamily
    ff.setAlarmSource("ALARM_SYSTEM_SOURCES");
    ff.setHelpUrl("http://www.test.com");
    Contact ct = new Contact();
    ct.setEmail("em1");
    ct.setGsm("gsm1");
    ct.setName("cont1");
    ff.setContact(ct);
    FaultCode fc = new FaultCode();
    fc.setValue(1);
    fc.setPriority(0);
    fc.setAction("action1");
    fc.setCause("cause1");
    fc.setConsequence("conseq1");
    fc.setProblemDescription("problem1");
    ff.addFaultCode(fc);
    FaultMember fm = new FaultMember();
    fm.setName("fmTest1");
    Location lc = new Location();
    lc.setBuilding("b2");
    lc.setFloor("f2");
    lc.setMnemonic("m2");
    lc.setPosition("p2");
    lc.setRoom("r2");
    fm.setLocation(lc);
    ff.addFaultMember(fm);
    exception = false;
    try {
        _alarmDAO.addFaultFamily(ff);
    } catch (Exception e) {
        exception = true;
    }
    assertFalse(exception);
    //Update FF information
    //ff.setAlarmSource("ALARM_SYSTEM_SOURCES2");//Can't be changed at the moment.
    ff.setHelpUrl("http://www.test2.com");
    ct.setEmail("em2");
    ct.setGsm("gsm2");
    ct.setName("cont2");
    try {
        _alarmDAO.updateFaultFamily(ff);
    } catch (Exception e) {
        exception = true;
    }
    assertFalse(exception);
    al1 = _alarmDAO.getAlarm("ffTest1:fmTest1:1");
    assertNotNull(al1);
    assertEquals("ALARM_SYSTEM_SOURCES", al1.getSource().getName());
    //assertEquals("ALARM_SYSTEM_SOURCES2",al1.getSource().getName());
    assertEquals("http://www.test2.com", al1.getHelpURL().toString());
    assertEquals("em2", al1.getPiquetEmail());
    assertEquals("gsm2", al1.getPiquetGSM());
    assertEquals("cont2", al1.getResponsiblePerson().getFamilyName());
    assertEquals(0, al1.getPriority().intValue());
    assertEquals("action1", al1.getAction());
    assertEquals("cause1", al1.getCause());
    assertEquals("conseq1", al1.getConsequence());
    assertEquals("problem1", al1.getProblemDescription());
    l = al1.getLocation();
    //assertEquals("b2",l.getBuilding());
    assertEquals("f2", l.getFloor());
    assertEquals("m2", l.getMnemonic());
    assertEquals("p2", l.getPosition());
    assertEquals("r2", l.getRoom());
    //Update FM Information
    fm.setName("fmTest2");
    lc.setBuilding("b3");
    lc.setFloor("f3");
    lc.setMnemonic("m3");
    lc.setPosition("p3");
    lc.setRoom("r3");
    try {
        _alarmDAO.updateFaultFamily(ff);
    } catch (Exception e) {
        exception = true;
    }
    assertFalse(exception);
    al1 = _alarmDAO.getAlarm("ffTest1:fmTest2:1");
    assertNotNull(al1);
    //assertEquals("ALARM_SYSTEM_SOURCES2",al1.getSource().getName());
    assertEquals("ALARM_SYSTEM_SOURCES", al1.getSource().getName());
    assertEquals("http://www.test2.com", al1.getHelpURL().toString());
    assertEquals("em2", al1.getPiquetEmail());
    assertEquals("gsm2", al1.getPiquetGSM());
    assertEquals("cont2", al1.getResponsiblePerson().getFamilyName());
    assertEquals(0, al1.getPriority().intValue());
    assertEquals("action1", al1.getAction());
    assertEquals("cause1", al1.getCause());
    assertEquals("conseq1", al1.getConsequence());
    assertEquals("problem1", al1.getProblemDescription());
    l = al1.getLocation();
    //assertEquals("b3",l.getBuilding());
    assertEquals("f3", l.getFloor());
    assertEquals("m3", l.getMnemonic());
    assertEquals("p3", l.getPosition());
    assertEquals("r3", l.getRoom());
    //Update FC Information
    fc.setValue(2);
    fc.setPriority(1);
    fc.setAction("action2");
    fc.setCause("cause2");
    fc.setConsequence("conseq2");
    fc.setProblemDescription("problem2");
    try {
        _alarmDAO.updateFaultFamily(ff);
    } catch (Exception e) {
        exception = true;
    }
    assertFalse(exception);
    al1 = _alarmDAO.getAlarm("ffTest1:fmTest2:2");
    assertNotNull(al1);
    //assertEquals("ALARM_SYSTEM_SOURCES2",al1.getSource().getName());
    assertEquals("ALARM_SYSTEM_SOURCES", al1.getSource().getName());
    assertEquals("http://www.test2.com", al1.getHelpURL().toString());
    assertEquals("em2", al1.getPiquetEmail());
    assertEquals("gsm2", al1.getPiquetGSM());
    assertEquals("cont2", al1.getResponsiblePerson().getFamilyName());
    assertEquals(1, al1.getPriority().intValue());
    assertEquals("action2", al1.getAction());
    assertEquals("cause2", al1.getCause());
    assertEquals("conseq2", al1.getConsequence());
    assertEquals("problem2", al1.getProblemDescription());
    l = al1.getLocation();
    //assertEquals("b3",l.getBuilding());
    assertEquals("f3", l.getFloor());
    assertEquals("m3", l.getMnemonic());
    assertEquals("p3", l.getPosition());
    assertEquals("r3", l.getRoom());
    //Update Add FM
    FaultMember fm2 = new FaultMember();
    fm2.setName("fmTest3");
    Location lc2 = new Location();
    lc2.setBuilding("b4");
    lc2.setFloor("f4");
    lc2.setMnemonic("m4");
    lc2.setPosition("p4");
    lc2.setRoom("r4");
    fm2.setLocation(lc2);
    ff.addFaultMember(fm2);
    exception = false;
    try {
        _alarmDAO.updateFaultFamily(ff);
    } catch (Exception e) {
        exception = true;
    }
    assertFalse(exception);
    al1 = _alarmDAO.getAlarm("ffTest1:fmTest3:2");
    assertNotNull(al1);
    //assertEquals("ALARM_SYSTEM_SOURCES2",al1.getSource().getName());
    assertEquals("ALARM_SYSTEM_SOURCES", al1.getSource().getName());
    assertEquals("http://www.test2.com", al1.getHelpURL().toString());
    assertEquals("em2", al1.getPiquetEmail());
    assertEquals("gsm2", al1.getPiquetGSM());
    assertEquals("cont2", al1.getResponsiblePerson().getFamilyName());
    assertEquals(1, al1.getPriority().intValue());
    assertEquals("action2", al1.getAction());
    assertEquals("cause2", al1.getCause());
    assertEquals("conseq2", al1.getConsequence());
    assertEquals("problem2", al1.getProblemDescription());
    l = al1.getLocation();
    //assertEquals("b4",l.getBuilding());
    assertEquals("f4", l.getFloor());
    assertEquals("m4", l.getMnemonic());
    assertEquals("p4", l.getPosition());
    assertEquals("r4", l.getRoom());
    //Update Add FC
    FaultCode fc2 = new FaultCode();
    fc2.setValue(3);
    fc2.setPriority(2);
    fc2.setAction("action3");
    fc2.setCause("cause3");
    fc2.setConsequence("conseq3");
    fc2.setProblemDescription("problem3");
    ff.addFaultCode(fc2);
    exception = false;
    try {
        _alarmDAO.updateFaultFamily(ff);
    } catch (Exception e) {
        exception = true;
    }
    assertFalse(exception);
    al1 = _alarmDAO.getAlarm("ffTest1:fmTest3:3");
    assertNotNull(al1);
    //assertEquals("ALARM_SYSTEM_SOURCES2",al1.getSource().getName());
    assertEquals("ALARM_SYSTEM_SOURCES", al1.getSource().getName());
    assertEquals("http://www.test2.com", al1.getHelpURL().toString());
    assertEquals("em2", al1.getPiquetEmail());
    assertEquals("gsm2", al1.getPiquetGSM());
    assertEquals("cont2", al1.getResponsiblePerson().getFamilyName());
    assertEquals(2, al1.getPriority().intValue());
    assertEquals("action3", al1.getAction());
    assertEquals("cause3", al1.getCause());
    assertEquals("conseq3", al1.getConsequence());
    assertEquals("problem3", al1.getProblemDescription());
    l = al1.getLocation();
    //assertEquals("b4",l.getBuilding());
    assertEquals("f4", l.getFloor());
    assertEquals("m4", l.getMnemonic());
    assertEquals("p4", l.getPosition());
    assertEquals("r4", l.getRoom());
    //Update Remove FM
    ff.removeFaultMember(fm);
    exception = false;
    try {
        _alarmDAO.updateFaultFamily(ff);
    } catch (Exception e) {
        exception = true;
    }
    assertFalse(exception);
    al1 = _alarmDAO.getAlarm("ffTest1:fmTest2:2");
    assertNull(al1);
    al1 = _alarmDAO.getAlarm("ffTest1:fmTest2:3");
    assertNull(al1);
    al1 = _alarmDAO.getAlarm("ffTest1:fmTest3:2");
    assertNotNull(al1);
    al1 = _alarmDAO.getAlarm("ffTest1:fmTest3:3");
    assertNotNull(al1);
    //Update Remove FC
    ff.removeFaultCode(fc);
    exception = false;
    try {
        _alarmDAO.updateFaultFamily(ff);
    } catch (Exception e) {
        exception = true;
    }
    assertFalse(exception);
    al1 = _alarmDAO.getAlarm("ffTest1:fmTest3:2");
    assertNull(al1);
    al1 = _alarmDAO.getAlarm("ffTest1:fmTest3:3");
    assertNotNull(al1);
    //Update Add Default FM
    FaultMemberDefault fmd = new FaultMemberDefault();
    lc = new Location();
    lc.setBuilding("b1");
    lc.setFloor("f1");
    lc.setMnemonic("m1");
    lc.setPosition("p1");
    lc.setRoom("r1");
    fmd.setLocation(lc);
    ff.setFaultMemberDefault(fmd);
    exception = false;
    try {
        _alarmDAO.updateFaultFamily(ff);
    } catch (Exception e) {
        exception = true;
    }
    assertFalse(exception);
    al1 = _alarmDAO.getAlarm("ffTest1:any:3");
    assertNotNull(al1);
    al1 = _alarmDAO.getAlarm("ffTest1:fmTest3:3");
    assertNotNull(al1);
//Update Remove Default FM
//ff.removeFaultMemberDefault(); Missing method?
/*
		exception = false;
		try{
			_alarmDAO.updateFaultFamily(ff);
		}catch(Exception e){
			exception = true;
		}
		assertFalse(exception);
		al1 = _alarmDAO.getAlarm("ffTest1:any:3");
		assertNull(al1);
		al1 = _alarmDAO.getAlarm("ffTest1:fmTest3:3");
		assertNotNull(al1);
		*/
}
Also used : FaultCode(alma.acs.alarmsystem.generated.FaultCode) FaultMember(alma.acs.alarmsystem.generated.FaultMember) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) Alarm(cern.laser.business.data.Alarm) Contact(alma.acs.alarmsystem.generated.Contact) Location(alma.acs.alarmsystem.generated.Location) FaultMemberDefault(alma.acs.alarmsystem.generated.FaultMemberDefault)

Aggregations

Contact (alma.acs.alarmsystem.generated.Contact)7 FaultFamily (alma.acs.alarmsystem.generated.FaultFamily)7 FaultCode (alma.acs.alarmsystem.generated.FaultCode)6 FaultMember (alma.acs.alarmsystem.generated.FaultMember)6 FaultMemberDefault (alma.acs.alarmsystem.generated.FaultMemberDefault)5 Location (alma.acs.alarmsystem.generated.Location)4 Alarm (cern.laser.business.data.Alarm)3 AlarmImpl (cern.laser.business.data.AlarmImpl)2 Category (cern.laser.business.data.Category)2 Location (cern.laser.business.data.Location)2 ResponsiblePerson (cern.laser.business.data.ResponsiblePerson)2 Source (cern.laser.business.data.Source)2 Triplet (cern.laser.business.data.Triplet)2 SourceDefinition (cern.laser.business.definition.data.SourceDefinition)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 InputSource (org.xml.sax.InputSource)2 Alarms (alma.acs.alarmsystem.generated.Alarms)1 Category (alma.acs.alarmsystem.generated.Category)1