Search in sources :

Example 16 with EmptyResultDataAccessException

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);
    }
}
Also used : EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) FacilityContactNotExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityContactNotExistsException)

Example 17 with EmptyResultDataAccessException

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;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) MailText(cz.metacentrum.perun.registrar.model.ApplicationMail.MailText) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) ApplicationMail(cz.metacentrum.perun.registrar.model.ApplicationMail) RowMapper(org.springframework.jdbc.core.RowMapper)

Example 18 with EmptyResultDataAccessException

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());
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) ServiceState(cz.metacentrum.perun.controller.model.ServiceState) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 19 with EmptyResultDataAccessException

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);
}
Also used : IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) DataRetrievalFailureException(org.springframework.dao.DataRetrievalFailureException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) PortalException(org.apereo.portal.PortalException) DataRetrievalFailureException(org.springframework.dao.DataRetrievalFailureException) SQLException(java.sql.SQLException) AuthorizationException(org.apereo.portal.AuthorizationException) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 20 with EmptyResultDataAccessException

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);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) Test(org.junit.Test)

Aggregations

EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)40 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)20 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)17 Attribute (cz.metacentrum.perun.core.api.Attribute)10 ConsistencyErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException)10 InternalErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException)10 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)9 ArrayList (java.util.ArrayList)9 User (cz.metacentrum.perun.core.api.User)6 Group (cz.metacentrum.perun.core.api.Group)5 HashSet (java.util.HashSet)5 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 RowMapper (org.springframework.jdbc.core.RowMapper)4 Member (cz.metacentrum.perun.core.api.Member)3 User (com.mapia.domain.User)2 ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)2 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)2 PerunNotifObject (cz.metacentrum.perun.notif.entities.PerunNotifObject)2 PerunNotifRegex (cz.metacentrum.perun.notif.entities.PerunNotifRegex)2