use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class FacilitiesManagerImpl method getFacilityContactGroup.
@Override
public ContactGroup getFacilityContactGroup(PerunSession sess, Facility facility, String name) throws InternalErrorException, FacilityContactNotExistsException {
try {
List<ContactGroup> contactGroups = jdbc.query("select " + facilityContactsMappingSelectQueryWithAllEntities + " from facility_contacts " + "left join facilities on facilities.id=facility_contacts.facility_id " + "left join owners on owners.id=facility_contacts.owner_id " + "left join users on users.id=facility_contacts.user_id " + "left join groups on groups.id=facility_contacts.group_id " + "where facility_contacts.facility_id=? and facility_contacts.name=?", FACILITY_CONTACT_MAPPER, facility.getId(), name);
contactGroups = mergeContactGroups(contactGroups);
if (contactGroups.size() == 1) {
return contactGroups.get(0);
} else {
throw new InternalErrorException("Merging group contacts for facility " + facility + " and contact name " + name + " failed, more than 1 object returned " + name);
}
} catch (EmptyResultDataAccessException ex) {
throw new FacilityContactNotExistsException(facility, name);
} catch (RuntimeException ex) {
throw new InternalErrorException(ex);
}
}
use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class MailManagerImpl method getMailById.
@Override
public ApplicationMail getMailById(PerunSession sess, Integer id) throws InternalErrorException, PrivilegeException {
// TODO authz
ApplicationMail mail = null;
// get mail def
try {
List<ApplicationMail> mails = jdbc.query("select id,app_type,form_id,mail_type,send from application_mails where id=?", new RowMapper<ApplicationMail>() {
@Override
public ApplicationMail mapRow(ResultSet rs, int arg1) throws SQLException {
return new ApplicationMail(rs.getInt("id"), AppType.valueOf(rs.getString("app_type")), rs.getInt("form_id"), MailType.valueOf(rs.getString("mail_type")), rs.getBoolean("send"));
}
}, id);
// set
if (mails.size() != 1) {
log.error("[MAIL MANAGER] Wrong number of mail definitions returned by unique params, expected 1 but was: " + mails.size());
throw new InternalErrorException("Wrong number of mail definitions returned by unique params, expected 1 but was: " + mails.size());
}
mail = mails.get(0);
} catch (EmptyResultDataAccessException ex) {
throw new InternalErrorException("Mail definition with ID=" + id + " doesn't exists.");
}
List<MailText> texts = new ArrayList<MailText>();
try {
texts = jdbc.query(MAIL_TEXTS_SELECT_BY_MAIL_ID, new RowMapper<MailText>() {
@Override
public MailText mapRow(ResultSet rs, int arg1) throws SQLException {
return new MailText(new Locale(rs.getString("locale")), rs.getString("subject"), rs.getString("text"));
}
}, mail.getId());
} catch (EmptyResultDataAccessException ex) {
// if no texts it's error
log.error("[MAIL MANAGER] Mail do not contains any text message: {}", ex);
return mail;
}
for (MailText text : texts) {
// fill localized messages
mail.getMessage().put(text.getLocale(), text);
}
return mail;
}
use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class PropagationStatsReaderImpl method getFacilityServicesState.
@Override
public List<ServiceState> getFacilityServicesState(PerunSession sess, Facility facility) throws ServiceNotExistsException, InternalErrorException, PrivilegeException {
if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility)) {
throw new PrivilegeException("getFacilityServicesState");
}
Map<Service, ServiceState> serviceStates = new HashMap<Service, ServiceState>();
// fill states for all services which are currently on facility
for (Service service : perun.getServicesManagerBl().getAssignedServices(sess, facility)) {
serviceStates.put(service, new ServiceState(service, facility));
try {
// fill global allowance state based on existing exec services
List<ExecService> execs = getGeneralServiceManager().listExecServices(sess, service.getId());
for (ExecService ex : execs) {
if (!ex.isEnabled())
serviceStates.get(service).setBlockedGlobally(true);
// fill facility allowance state based on existing exec services
if (getGeneralServiceManager().isExecServiceDeniedOnFacility(ex, facility))
serviceStates.get(service).setBlockedOnFacility(true);
}
} catch (EmptyResultDataAccessException ex) {
// service has no exec services -> blocked globally
serviceStates.get(service).setBlockedGlobally(true);
}
// service has destination on facility
serviceStates.get(service).setHasDestinations(!perun.getServicesManagerBl().getDestinations(sess, service, facility).isEmpty());
}
// fill states for all tasks on facility
List<Task> tasks = taskDao.listAllTasksForFacility(facility.getId());
for (Task task : tasks) {
Service taskService = task.getExecService().getService();
ServiceState serviceState = serviceStates.get(taskService);
if (serviceState == null) {
serviceState = new ServiceState(taskService, facility);
serviceStates.put(taskService, serviceState);
// fill destinations if service was not assigned
serviceStates.get(taskService).setHasDestinations(!perun.getServicesManagerBl().getDestinations(sess, taskService, facility).isEmpty());
}
// fill service state
if (ExecService.ExecServiceType.GENERATE.equals(task.getExecService().getExecServiceType())) {
serviceState.setGenTask(task);
} else {
serviceState.setSendTask(task);
}
if (!task.getExecService().isEnabled()) {
serviceStates.get(taskService).setBlockedGlobally(true);
}
if (getGeneralServiceManager().isExecServiceDeniedOnFacility(task.getExecService(), facility))
serviceStates.get(taskService).setBlockedOnFacility(true);
}
return new ArrayList<ServiceState>(serviceStates.values());
}
use of org.springframework.dao.EmptyResultDataAccessException in project uPortal by Jasig.
the class RDBMDistributedLayoutStore method getPortletEntity.
private IPortletEntity getPortletEntity(String fName, String layoutNodeId, int userId) {
//Try getting the entity
final IPortletEntity portletEntity = this.portletEntityDao.getPortletEntity(layoutNodeId, userId);
if (portletEntity != null) {
return portletEntity;
}
//Load the portlet definition
final IPortletDefinition portletDefinition;
try {
portletDefinition = this.portletDefinitionRegistry.getPortletDefinitionByFname(fName);
} catch (Exception e) {
throw new DataRetrievalFailureException("Failed to retrieve ChannelDefinition for fName='" + fName + "'", e);
}
//The channel definition for the fName MUST exist for this class to function
if (portletDefinition == null) {
throw new EmptyResultDataAccessException("No ChannelDefinition exists for fName='" + fName + "'", 1);
}
//create the portlet entity
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
return this.portletEntityDao.createPortletEntity(portletDefinitionId, layoutNodeId, userId);
}
use of org.springframework.dao.EmptyResultDataAccessException in project camel by apache.
the class SqlRouteTest method testInsert.
@Test
public void testInsert() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.sendBody("direct:insert", new Object[] { 10, "test", "test" });
mock.assertIsSatisfied();
try {
String projectName = jdbcTemplate.queryForObject("select project from projects where id = 10", String.class);
assertEquals("test", projectName);
} catch (EmptyResultDataAccessException e) {
fail("no row inserted");
}
Integer actualUpdateCount = mock.getExchanges().get(0).getIn().getHeader(SqlConstants.SQL_UPDATE_COUNT, Integer.class);
assertEquals((Integer) 1, actualUpdateCount);
}
Aggregations