use of cern.laser.business.data.AdminUser 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");
}
use of cern.laser.business.data.AdminUser in project ACS by ACS-Community.
the class AlarmDefinitionServiceImpl method getAlarmDefinitions.
public Collection getAlarmDefinitions(String userId) throws LaserDefinitionException {
if (userId == null) {
throw new LaserDefinitionNotValidException("user id is null");
}
AdminUser admin_user = adminUserDAO.findAdminUser(userId);
LOGGER.info("getting administered alarms for user : " + admin_user.getName());
Collection result = new ArrayList();
String[] administered_sources = adminUserDAO.getAdministeredSources(userId);
for (int i = 0; i < administered_sources.length; i++) {
Source source = sourceDAO.findSource(administered_sources[i]);
String[] alarms = sourceDAO.getAlarms(source.getSourceId());
for (int j = 0; j < alarms.length; j++) {
result.add(getAlarmDefinition(alarms[j]));
}
}
LOGGER.info("found " + result.size() + " administered alarms");
return result;
}
use of cern.laser.business.data.AdminUser in project ACS by ACS-Community.
the class AlarmDefinitionServiceImpl method createNodeLinkInternal.
private void createNodeLinkInternal(String userId, ReductionLink link) throws LaserDefinitionException {
Alarm[] parent_child = validateReductionLink(link);
AdminUser admin_user = adminUserDAO.findAdminUser(userId);
try {
LOGGER.info("user " + admin_user.getName() + " creating node link : " + link);
//alarmDAO.findAlarm(link.getParent().getAlarmId());
Alarm parent = parent_child[0];
//alarmDAO.findAlarm(link.getChild().getAlarmId());
Alarm child = parent_child[1];
parent.addNodeChild(child);
alarmDAO.updateAlarm(parent);
LOGGER.info("node link created");
} catch (Exception e) {
throw new LaserRuntimeException("unable to create the node link " + link + " : " + e.getMessage(), e);
}
}
use of cern.laser.business.data.AdminUser in project ACS by ACS-Community.
the class AdminUserDefinitionServiceImpl method removeAdminUser.
public void removeAdminUser(String name) throws LaserDefinitionException {
LOGGER.info("removing admin user : " + name);
AdminUser admin_user = adminUserDAO.getAdminUserByName(name);
if (admin_user == null) {
throw new LaserDefinitionNotFoundException("a user " + name + " does not exists");
}
adminUserDAO.deleteAdminUser(admin_user);
admin_user = null;
LOGGER.info("user " + name + " removed");
}
use of cern.laser.business.data.AdminUser in project ACS by ACS-Community.
the class AdminUserDefinitionServiceImpl method getAdminUsers.
// public AdminUser findAdminUser(Integer userId) throws LaserDefinitionException {
// if (userId == null) throw new LaserDefinitionNotAllowedException("userId is null");
//
// AdminUser admin_user = adminUserDAO.getAdminUser(userId);
// if (admin_user == null) {
// throw new LaserDefinitionNotFoundException("unable to find admin user "+userId);
// }
//
// return admin_user;
// }
public Collection getAdminUsers() throws LaserDefinitionException {
try {
AdminUser[] users = adminUserDAO.findAllAdminUsers();
Collection result = new ArrayList(users.length);
for (int i = 0; i < users.length; i++) {
result.add(users[i].getUserId());
}
return result;
} catch (Exception e) {
throw new LaserDefinitionException("unable to get admin users", e);
}
}
Aggregations