Search in sources :

Example 16 with ExchangeDaoException

use of eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException in project UVMS-ExchangeModule-APP by UnionVMS.

the class ServiceRegistryModelBean method unregisterService.

@Override
public ServiceResponseType unregisterService(ServiceType serviceType, String username) throws ExchangeModelException {
    // Look for existing service
    Service service = dao.getServiceByServiceClassName(serviceType.getServiceClassName());
    ServiceResponseType response = null;
    if (service != null) {
        service.setActive(false);
        service.setStatus(StatusType.STOPPED.name());
        service.getServiceCapabilityList().clear();
        service.getServiceSettingList().clear();
        service.setUpdatedBy(username);
        Service updateService = dao.updateService(service);
        response = ServiceMapper.toServiceModel(updateService);
    }
    if (response != null) {
        return response;
    }
    // TODO handle unable to unregister
    throw new ExchangeDaoException("[ No service to unregister ]");
}
Also used : ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) Service(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service)

Example 17 with ExchangeDaoException

use of eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException in project UVMS-ExchangeModule-APP by UnionVMS.

the class UnsentModelBean method createMessage.

@Override
public String createMessage(UnsentMessageType message, String username) throws ExchangeModelException {
    if (message == null) {
        throw new InputArgumentException("No message to create");
    }
    try {
        UnsentMessage entity = UnsentMessageMapper.toEntity(message, username);
        UnsentMessage persistedEntity = dao.create(entity);
        UnsentMessageType model = UnsentMessageMapper.toModel(persistedEntity);
        return model.getMessageId();
    } catch (ExchangeDaoException ex) {
        LOG.error("[ Error when creating unsent message ] {}", ex.getMessage());
        throw new ExchangeModelException("Error when creating unsent message ");
    }
}
Also used : UnsentMessageType(eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType) InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) UnsentMessage(eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)

Example 18 with ExchangeDaoException

use of eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException in project UVMS-ExchangeModule-APP by UnionVMS.

the class UnsentModelBean method removeMessage.

@Override
public String removeMessage(String unsentMessageId) throws ExchangeModelException {
    if (unsentMessageId == null) {
        throw new InputArgumentException("No message to remove");
    }
    try {
        UnsentMessage entity = dao.getByGuid(unsentMessageId);
        if (entity != null) {
            String guid = entity.getGuid();
            dao.remove(entity);
            return guid;
        } else {
            LOG.error("[ Error when removing unsent message ]");
            throw new ExchangeModelException("Error when removing unsent message ");
        }
    } catch (ExchangeDaoException ex) {
        LOG.error("[ Error when creating unsent message ] {}", ex.getMessage());
        throw new ExchangeModelException("Error when creating unsent message ");
    }
}
Also used : InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) UnsentMessage(eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)

Example 19 with ExchangeDaoException

use of eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogDaoBean method getExchangeLogListPaginated.

@Override
public List<ExchangeLog> getExchangeLogListPaginated(Integer page, Integer listSize, String sql, List<SearchValue> searchKeyValues) throws ExchangeDaoException {
    try {
        LOG.debug("SQL QUERY IN LIST PAGINATED: " + sql);
        TypedQuery<ExchangeLog> query = em.createQuery(sql, ExchangeLog.class);
        HashMap<ExchangeSearchField, List<SearchValue>> orderedValues = SearchFieldMapper.combineSearchFields(searchKeyValues);
        setQueryParameters(query, orderedValues);
        query.setFirstResult(listSize * (page - 1));
        query.setMaxResults(listSize);
        return query.getResultList();
    } catch (IllegalArgumentException e) {
        LOG.error("[ Error getting exchangelog list paginated ] {}", e.getMessage());
        throw new ExchangeDaoException("[ Error when getting list ] ");
    } catch (Exception e) {
        LOG.error("[ Error getting exchangelog list paginated ]  {}", e.getMessage());
        throw new ExchangeDaoException("[ Error when getting list ] ");
    }
}
Also used : ExchangeSearchField(eu.europa.ec.fisheries.uvms.exchange.search.ExchangeSearchField) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) ArrayList(java.util.ArrayList) List(java.util.List) NoResultException(javax.persistence.NoResultException) NoEntityFoundException(eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) PersistenceException(javax.persistence.PersistenceException) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)

Example 20 with ExchangeDaoException

use of eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogDaoBean method getExchangeLogByGuid.

@Override
public ExchangeLog getExchangeLogByGuid(String logGuid, TypeRefType typeRefType) throws ExchangeDaoException {
    try {
        TypedQuery<ExchangeLog> query = em.createNamedQuery(ExchangeConstants.LOG_BY_GUID, ExchangeLog.class);
        query.setParameter("typeRefType", typeRefType);
        query.setParameter("guid", logGuid);
        return query.getSingleResult();
    } catch (NoResultException e) {
        LOG.error("[ Error when getting entity by ID. ] {}", e.getMessage());
        throw new NoEntityFoundException("[ Error when getting entity by ID. ]");
    } catch (Exception e) {
        LOG.error("[ Error when getting entity by ID. ] {}", e.getMessage());
        throw new ExchangeDaoException("[ Error when getting entity by ID. ] ");
    }
}
Also used : ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) NoEntityFoundException(eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException) NoResultException(javax.persistence.NoResultException) NoResultException(javax.persistence.NoResultException) NoEntityFoundException(eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) PersistenceException(javax.persistence.PersistenceException) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)

Aggregations

ExchangeDaoException (eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException)22 NoEntityFoundException (eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException)10 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)10 ExchangeLog (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)9 NoResultException (javax.persistence.NoResultException)9 InputArgumentException (eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException)8 ArrayList (java.util.ArrayList)6 PersistenceException (javax.persistence.PersistenceException)5 ExchangeLogStatus (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus)4 EntityExistsException (javax.persistence.EntityExistsException)4 ExchangeLogType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType)3 Service (eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service)3 ServiceSetting (eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceSetting)3 UnsentMessage (eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage)3 TypeRefType (eu.europa.ec.fisheries.schema.exchange.v1.TypeRefType)2 UnsentMessageType (eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType)2 ServiceCapability (eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceCapability)2 ExchangeLogStatusHistoryType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusHistoryType)1 ExchangeLogStatusType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusType)1 LogWithRawMsgAndType (eu.europa.ec.fisheries.schema.exchange.v1.LogWithRawMsgAndType)1