Search in sources :

Example 31 with Category

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

the class CategoryDefinitionServiceImpl method removeCategory.

public void removeCategory(String userId, CategoryDefinition categoryDefinition) throws LaserDefinitionException {
    if (categoryDefinition == null) {
        throw new LaserDefinitionNotValidException("category is null");
    }
    Category category = categoryDAO.getCategoryByPath(categoryDefinition.getPath());
    if (category == null) {
        throw new LaserDefinitionNotFoundException("category with path " + categoryDefinition.getPath() + " does not exist");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    AdminUser laser_user = adminUserDAO.findByLaserAdminUser();
    if (!admin_user.administersCategory(category.getCategoryId())) {
        throw new LaserDefinitionNotAllowedException("not in category administrators : " + categoryDefinition);
    }
    if (categoryDAO.getAlarms(category.getCategoryId()).length != 0) {
        throw new LaserDefinitionNotAllowedException("category has attached alarms");
    }
    try {
        LOGGER.info("user " + admin_user.getName() + " removing category : " + categoryDefinition);
        admin_user.removeAdministeredCategory(category);
        laser_user.removeAdministeredCategory(category);
        categoryDAO.deleteCategory(category);
        adminUserDAO.updateAdminUser(admin_user);
        adminUserDAO.updateAdminUser(laser_user);
        LOGGER.info("category removed");
    } catch (Exception e) {
        throw new LaserDefinitionException("unable to remove category " + categoryDefinition + " : " + e.getMessage(), e);
    }
}
Also used : LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) Category(cern.laser.business.data.Category) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) LaserDefinitionException(cern.laser.business.definition.LaserDefinitionException) AdminUser(cern.laser.business.data.AdminUser) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) LaserDefinitionException(cern.laser.business.definition.LaserDefinitionException) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException)

Example 32 with Category

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

the class CategoryDefinitionServiceImpl method removeCategoryLink.

public void removeCategoryLink(String userId, CategoryLink link) throws LaserDefinitionException {
    if (link == null) {
        throw new LaserDefinitionNotValidException("category/alarm link is null");
    }
    if (link.getCategory() == null) {
        throw new LaserDefinitionNotValidException("malformed category/alarm link: category is null");
    }
    if (link.getAlarm() == null) {
        throw new LaserDefinitionNotValidException("malformed category/alarm link: alarm is null");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    Category category = categoryDAO.getCategoryByPath(link.getCategory().getPath());
    if (category == null) {
        throw new LaserDefinitionNotFoundException("category with path " + link.getCategory().getPath() + " does not exist");
    }
    if (!admin_user.administersCategory(category.getCategoryId())) {
        throw new LaserDefinitionNotAllowedException("not an administrators for the category : " + link.getCategory());
    }
    Alarm alarm = alarmDAO.getAlarm(link.getAlarm().getAlarmId());
    if (alarm == null) {
        throw new LaserDefinitionNotFoundException("alarm " + link.getAlarm().getAlarmId() + " does not exist");
    }
    if (!category.containsAlarm(alarm)) {
        throw new LaserDefinitionNotFoundException("category/alarm link not defined : " + link);
    }
    try {
        LOGGER.info("user " + admin_user.getName() + " removing category link : " + link);
        category.removeAlarm(alarm);
        categoryDAO.flushCategory();
        alarmCache.invalidate(alarm.getAlarmId());
    //      Alarm surveillance_alarm = alarmDAO.findAlarm(alarm.getSource().getSurveillanceAlarmId());
    //      if (!categoryDAO.hasAlarmsForSource(category.getCategoryId(), alarm.getSource().getSourceId())) {
    //        category.removeAlarm(surveillance_alarm);
    //        alarmCache.invalidate(surveillance_alarm.getAlarmId());
    //      }
    //      categoryDAO.updateCategory(category);
    } catch (AlarmCacheException e) {
        LOGGER.error("unable to propagate category/alarm link : " + link, e);
    }
    LOGGER.info("category/alarm link removed");
}
Also used : LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) Category(cern.laser.business.data.Category) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) Alarm(cern.laser.business.data.Alarm) AdminUser(cern.laser.business.data.AdminUser) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException)

Example 33 with Category

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

the class ACSAlarmCacheImpl method buildUnconfiguredAlarm.

/**
	 * Build a unconfigured alarm from the passed ID.
	 * 
	 * A unconfigured alarm has no data but the triplet generated
	 * from the identifier.
	 * I associate the lowest priority and a user property
	 * to be recognized by clients as being generated by the AS instead
	 * of being retrieved from the configuration database.
	 * <P>
	 * The property identifying this alarm as generated by the AS is:
	 * <Name="AlarmServerProp", Value="UnconfiguredAlarm">
	 * <P>
	 * The alarm is associated to the ROOT category.
	 * 
	 * @param alarmID The ID of the alarm
	 * @return The default alarm
	 */
private Alarm buildUnconfiguredAlarm(String alarmID) {
    if (alarmID == null || alarmID.isEmpty()) {
        throw new IllegalArgumentException("Invalid null or empty alarm ID!");
    }
    String[] parts = alarmID.split(":");
    if (parts.length != 3) {
        throw new IllegalArgumentException("Invalid alarm ID: " + alarmID);
    }
    String FF = parts[0];
    String FM = parts[1];
    Integer FC;
    try {
        FC = Integer.valueOf(parts[2]);
    } catch (NumberFormatException nfe) {
        throw new IllegalArgumentException("Invalid FC in alarm ID: " + alarmID, nfe);
    }
    AlarmImpl alarm = new AlarmImpl();
    alarm.setMultiplicityChildrenIds(new HashSet());
    alarm.setMultiplicityParentIds(new HashSet());
    alarm.setNodeChildrenIds(new HashSet());
    alarm.setNodeParentIds(new HashSet());
    alarm.setAction(EMPTY_STRING);
    alarm.setTriplet(new Triplet(FF, FM, FC));
    alarm.setCategories(new HashSet<Category>());
    alarm.setCause(EMPTY_STRING);
    alarm.setConsequence(EMPTY_STRING);
    alarm.setProblemDescription(EMPTY_STRING);
    alarm.setHelpURL(null);
    alarm.setInstant(false);
    Location location = new Location("0", EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING);
    alarm.setLocation(location);
    alarm.setPiquetEmail(EMPTY_STRING);
    alarm.setPiquetGSM(EMPTY_STRING);
    alarm.setPriority(3);
    ResponsiblePerson responsible = new ResponsiblePerson(1, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING);
    alarm.setResponsiblePerson(responsible);
    SourceDefinition srcDef = new SourceDefinition("ALARM_SYSTEM_SOURCES", "SOURCE", EMPTY_STRING, 15, 1);
    Source src = new Source(srcDef, responsible);
    alarm.setSource(src);
    alarm.setIdentifier(alarm.getTriplet().toIdentifier());
    // Build the status in order to associate the property
    Properties userProps = new Properties();
    userProps.put(alarmServerPropkey, undocumentedAlarmProp);
    StatusImpl status = new StatusImpl(false, false, false, false, false, EMPTY_STRING, new Timestamp(0), new Timestamp(0), new Timestamp(0), userProps);
    alarm.setStatus(status);
    // Category association
    //
    // A category for this FF can be already set (this is the case when a new FC/FM is found
    // but the FF has already been associated to a category)
    // In practice a new category has to be defined only if the FF is unknown.
    Category[] categories = categoryDAO.findAllCategories();
    Set<Category> categoriesSet = new HashSet<Category>();
    for (Category cat : categories) {
        if (cat.containsAlarm(alarm)) {
            categoriesSet.add(cat);
        }
    }
    if (!categoriesSet.isEmpty()) {
        System.out.println("Alarm " + alarm.getAlarmId() + " already associated to categories");
    } else {
        System.out.println("Alarm " + alarm.getAlarmId() + " has no associated category");
        Category root = categoryDAO.findCategoryByPath("ROOT");
        categoriesSet.add(root);
        alarm.setCategories(categoriesSet);
        root.addAlarm(alarm);
    }
    return alarm;
}
Also used : SourceDefinition(cern.laser.business.definition.data.SourceDefinition) Category(cern.laser.business.data.Category) Triplet(cern.laser.business.data.Triplet) StatusImpl(cern.laser.business.data.StatusImpl) Properties(java.util.Properties) Timestamp(java.sql.Timestamp) Source(cern.laser.business.data.Source) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) AlarmImpl(cern.laser.business.data.AlarmImpl) HashSet(java.util.HashSet) Location(cern.laser.business.data.Location)

Example 34 with Category

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

the class SourceDefinitionServiceImpl method removeSource.

public void removeSource(String userId, SourceDefinition sourceDefinition) throws LaserDefinitionException {
    if (sourceDefinition == null) {
        throw new LaserDefinitionNotValidException("source is null");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    AdminUser laser_user = adminUserDAO.findByLaserAdminUser();
    Source source = sourceDAO.findSource(sourceDefinition.getSourceId());
    if (!admin_user.administersSource(source)) {
        throw new LaserDefinitionNotAllowedException("not in source administrators");
    }
    if (sourceDAO.getAlarms(sourceDefinition.getSourceId()).length > 1) {
        throw new LaserDefinitionNotAllowedException("source has attached alarms");
    }
    try {
        LOGGER.info("user " + admin_user.getName() + " removing source : " + sourceDefinition);
        alarmDefinitionService.removeAlarm(adminUserDAO.findByLaserAdminUser().getUserId(), alarmDAO.findAlarm(source.getSurveillanceAlarmId()).getDefinition());
        admin_user.removeAdministeredSource(source);
        laser_user.removeAdministeredSource(source);
        sourceDAO.deleteSource(source);
        source = null;
        String category_path = new String(SOURCE_CATEGORY_PATH_PREFIX + sourceDefinition.getName());
        Category parent_category = categoryDAO.findCategoryByPath(SOURCES_CATEGORY_ROOT_PATH);
        Category category = categoryDAO.findCategoryByPath(category_path);
        parent_category.removeChildCategory(category);
        admin_user.removeAdministeredCategory(category);
        laser_user.removeAdministeredCategory(category);
        categoryDAO.deleteCategory(category);
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("removed default category " + category_path + " for source " + sourceDefinition.getName());
        adminUserDAO.updateAdminUser(admin_user);
        adminUserDAO.updateAdminUser(laser_user);
        LOGGER.info("removed source " + sourceDefinition.getName());
    } catch (Exception e) {
        throw new LaserDefinitionException("unable to remove source " + sourceDefinition + " : " + e.getMessage(), e);
    }
}
Also used : LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) Category(cern.laser.business.data.Category) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) LaserDefinitionException(cern.laser.business.definition.LaserDefinitionException) AdminUser(cern.laser.business.data.AdminUser) Source(cern.laser.business.data.Source) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) LaserDefinitionException(cern.laser.business.definition.LaserDefinitionException) LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException)

Example 35 with Category

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

the class ACSCategoryDAOImpl method deleteCategory.

public void deleteCategory(Category category) {
    Integer id = category.getCategoryId();
    if (id == null)
        throw new IllegalStateException();
    Category previous = categories.get(id);
    categories.remove(id);
    // this one was in catPath, so remove that one instead
    // have to use values(), because the path may have changed,
    // but mapping didn't
    catPathToCategory.values().remove(previous);
}
Also used : Category(cern.laser.business.data.Category)

Aggregations

Category (cern.laser.business.data.Category)47 Alarm (cern.laser.business.data.Alarm)16 CategoryImpl (cern.laser.business.data.CategoryImpl)14 HashSet (java.util.HashSet)9 AdminUser (cern.laser.business.data.AdminUser)8 LaserDefinitionNotValidException (cern.laser.business.definition.LaserDefinitionNotValidException)8 LaserDefinitionDuplicationException (cern.laser.business.definition.LaserDefinitionDuplicationException)7 LaserDefinitionNotAllowedException (cern.laser.business.definition.LaserDefinitionNotAllowedException)7 LaserDefinitionNotFoundException (cern.laser.business.definition.LaserDefinitionNotFoundException)7 CategoryDefinition (alma.alarmsystem.alarmmessage.generated.CategoryDefinition)6 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)6 AlarmCacheException (cern.laser.business.cache.AlarmCacheException)6 Source (cern.laser.business.data.Source)6 ResponsiblePerson (cern.laser.business.data.ResponsiblePerson)5 AlarmCategoryDefinitions (alma.alarmsystem.alarmmessage.generated.AlarmCategoryDefinitions)4 AlarmCategoryLinkDefinitionListType (alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkDefinitionListType)4 AlarmCategoryLinkType (alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkType)4 AlarmDefinition (alma.alarmsystem.alarmmessage.generated.AlarmDefinition)4 AlarmImpl (cern.laser.business.data.AlarmImpl)4 LaserDefinitionException (cern.laser.business.definition.LaserDefinitionException)4