Search in sources :

Example 1 with CategoryDefinition

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

the class SourceDefinitionServiceImpl method createSource.

public void createSource(String userId, SourceDefinition sourceDefinition) throws LaserDefinitionException {
    if (sourceDefinition == null) {
        throw new LaserDefinitionNotValidException("source is null");
    }
    Source source = sourceDAO.getSource(sourceDefinition.getSourceId());
    if (source != null) {
        throw new LaserDefinitionDuplicationException("source " + sourceDefinition.getSourceId() + " already exist");
    }
    if (sourceDefinition.getResponsiblePersonId() == null) {
        throw new LaserDefinitionNotValidException("responsible id for the source definition is null");
    }
    ResponsiblePerson responsible = responsiblePersonDAO.getResponsiblePerson(sourceDefinition.getResponsiblePersonId());
    if (responsible == null) {
        throw new LaserDefinitionNotValidException("responsible with id " + sourceDefinition.getResponsiblePersonId() + " does not exist");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    AdminUser laser_user = adminUserDAO.findByLaserAdminUser();
    LOGGER.info("user " + admin_user.getName() + " creating source : " + sourceDefinition);
    // create the source
    source = new Source(sourceDefinition, responsible);
    CategoryDefinition category_definition = new CategoryDefinition(SOURCE_CATEGORY_PATH_PREFIX + sourceDefinition.getName(), "Category for source " + sourceDefinition.getName());
    Category parent_category = categoryDAO.findCategoryByPath(category_definition.getParentPath());
    Category category = new CategoryImpl(category_definition);
    parent_category.addChildCategory(category);
    categoryDAO.saveCategory(category);
    admin_user.addAdministeredCategory(category);
    laser_user.addAdministeredCategory(category);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("default category " + category_definition.getPath() + "created for source " + sourceDefinition.getName());
    source.setSurveillanceAlarmId(alarmDAO.findLaserSurveillanceAlarmId());
    sourceDAO.saveSource(source);
    // create the source surveillance alarm
    AlarmDefinition surveillance_alarm_definition = (AlarmDefinition) SOURCE_SURVEILLANCE_ALARM_DEFINITION.clone();
    surveillance_alarm_definition.setFaultMember(sourceDefinition.getName());
    surveillance_alarm_definition.setIdentifier(sourceDefinition.getName());
    Alarm surveillance_alarm = new AlarmImpl(surveillance_alarm_definition, source, responsible);
    Category surveillance_category = categoryDAO.findBySurveillanceCategory();
    surveillance_category.addAlarm(surveillance_alarm);
    category.addAlarm(surveillance_alarm);
    alarmDAO.saveAlarm(surveillance_alarm);
    categoryDAO.updateCategory(surveillance_category);
    categoryDAO.updateCategory(category);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("surveillance alarm created for source " + sourceDefinition.getName());
    source.setSurveillanceAlarmId(surveillance_alarm.getAlarmId());
    sourceDAO.updateSource(source);
    admin_user.addAdministeredSource(source);
    laser_user.addAdministeredSource(source);
    adminUserDAO.updateAdminUser(admin_user);
    adminUserDAO.updateAdminUser(laser_user);
    LOGGER.info("source created");
}
Also used : CategoryImpl(cern.laser.business.data.CategoryImpl) LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) Category(cern.laser.business.data.Category) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) AlarmDefinition(cern.laser.business.definition.data.AlarmDefinition) Alarm(cern.laser.business.data.Alarm) AlarmImpl(cern.laser.business.data.AlarmImpl) AdminUser(cern.laser.business.data.AdminUser) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) Source(cern.laser.business.data.Source) CategoryDefinition(cern.laser.business.definition.data.CategoryDefinition)

Example 2 with CategoryDefinition

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

the class ACSCategoryDAOTest method testUpdateCategory.

/**
	 * Test if updating a category works
	 */
public void testUpdateCategory() {
    // The root is the only one having childs
    Category root = categoryDAO.getCategoryByPath("ROOT");
    assertNotNull("Found a null ROOT category", root);
    // Get the number of defined categories
    Integer[] IDs = categoryDAO.getAllCategoryIDs();
    int len = IDs.length;
    // get a category to update
    Category cat = categoryDAO.getCategory(root.getCategoryId() + 1);
    assertNotNull(cat);
    CategoryDefinition def = cat.getDefinition();
    assertNotNull(def);
    String newDesc = "New Description";
    def.setDescription(newDesc);
    cat.setDefinition(def);
    // Update the category
    categoryDAO.updateCategory(cat);
    // Check if the size of the categories is right
    assertEquals(len, categoryDAO.getAllCategoryIDs().length);
    // Get the category
    cat = categoryDAO.getCategory(cat.getCategoryId());
    assertNotNull("Category not found", cat);
    // Check if the description has been updated
    assertEquals(newDesc, cat.getDescription());
}
Also used : Category(cern.laser.business.data.Category) CategoryDefinition(cern.laser.business.definition.data.CategoryDefinition)

Aggregations

Category (cern.laser.business.data.Category)2 CategoryDefinition (cern.laser.business.definition.data.CategoryDefinition)2 AdminUser (cern.laser.business.data.AdminUser)1 Alarm (cern.laser.business.data.Alarm)1 AlarmImpl (cern.laser.business.data.AlarmImpl)1 CategoryImpl (cern.laser.business.data.CategoryImpl)1 ResponsiblePerson (cern.laser.business.data.ResponsiblePerson)1 Source (cern.laser.business.data.Source)1 LaserDefinitionDuplicationException (cern.laser.business.definition.LaserDefinitionDuplicationException)1 LaserDefinitionNotValidException (cern.laser.business.definition.LaserDefinitionNotValidException)1 AlarmDefinition (cern.laser.business.definition.data.AlarmDefinition)1