private void newPluginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newPluginButtonActionPerformed PluginEditor dialog = new PluginEditor(new javax.swing.JFrame(), true); dialog.setVisible(true); while (dialog.isVisible()) { try { Thread.sleep(1000); } catch (InterruptedException ex) { logger.error(ex.getMessage(),ex); } } if(dialog.getPlugin()==null) return; EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); try { em.persist(dialog.getPlugin()); } catch (EntityExistsException e) { javax.swing.JOptionPane.showMessageDialog(this, "The plugin is already registered!", "Warning", JOptionPane.WARNING_MESSAGE); em.getTransaction().rollback(); em.close(); return; } em.getTransaction().commit(); em.close(); inactivemodel.addElement(dialog.getPlugin()); }
public <T extends WithId<T>> T create(final T entity) { Kind kind = entity.getKind(); Map<String, T> cache = caches.getCache(kind.getModelName()); Optional<String> id = entity.getId(); String idVal; final T entityToCreate; if (!id.isPresent()) { idVal = KeyGenerator.createKey(); entityToCreate = entity.withId(idVal); } else { idVal = id.get(); if (cache.containsKey(idVal)) { throw new EntityExistsException("There already exists a " + kind + " with id " + idVal); } entityToCreate = entity; } this.<T, T>doWithDataAccessObject(kind.getModelClass(), d -> d.create(entityToCreate)); cache.put(idVal, entityToCreate); broadcast("created", kind.getModelName(), idVal); return entityToCreate; }
@Override public WebServer createWebServer(final WebServer webServer, final String createdBy) { try { final JpaWebServer jpaWebServer = new JpaWebServer(); jpaWebServer.setName(webServer.getName()); jpaWebServer.setHost(webServer.getHost()); jpaWebServer.setPort(webServer.getPort()); jpaWebServer.setHttpsPort(webServer.getHttpsPort()); jpaWebServer.setStatusPath(webServer.getStatusPath().getPath()); jpaWebServer.setCreateBy(createdBy); jpaWebServer.setState(webServer.getState()); jpaWebServer.setApacheHttpdMedia(webServer.getApacheHttpdMedia() == null ? null : new ModelMapper() .map(webServer.getApacheHttpdMedia(), JpaMedia.class)); return webServerFrom(create(jpaWebServer)); } catch (final EntityExistsException eee) { LOGGER.error("Error creating web server {}", webServer, eee); throw new EntityExistsException("Web server with name already exists: " + webServer, eee); } }
@Override public WebServer updateWebServer(final WebServer webServer, final String createdBy) { try { final JpaWebServer jpaWebServer = findById(webServer.getId().getId()); jpaWebServer.setName(webServer.getName()); jpaWebServer.setHost(webServer.getHost()); jpaWebServer.setPort(webServer.getPort()); jpaWebServer.setHttpsPort(webServer.getHttpsPort()); jpaWebServer.setStatusPath(webServer.getStatusPath().getPath()); jpaWebServer.setCreateBy(createdBy); return webServerFrom(update(jpaWebServer)); } catch (final EntityExistsException eee) { LOGGER.error("Error updating web server {}", webServer, eee); throw new EntityExistsException("Web Server Name already exists", eee); } }
@Override public JpaApplication createApplication(CreateApplicationRequest createApplicationRequest, JpaGroup jpaGroup) { final JpaApplication jpaApp = new JpaApplication(); jpaApp.setName(createApplicationRequest.getName()); jpaApp.setGroup(jpaGroup); jpaApp.setWebAppContext(createApplicationRequest.getWebAppContext()); jpaApp.setSecure(createApplicationRequest.isSecure()); jpaApp.setLoadBalanceAcrossServers(createApplicationRequest.isLoadBalanceAcrossServers()); jpaApp.setUnpackWar(createApplicationRequest.isUnpackWar()); try { return create(jpaApp); } catch (final EntityExistsException eee) { LOGGER.error("Error creating app with request {} in group {}", createApplicationRequest, jpaGroup, eee); throw new EntityExistsException("App already exists: " + createApplicationRequest, eee); } }
@Override public JpaApplication updateApplication(UpdateApplicationRequest updateApplicationRequest, JpaApplication jpaApp, JpaGroup jpaGroup) { final Identifier<Application> appId = updateApplicationRequest.getId(); if (jpaApp != null) { jpaApp.setName(updateApplicationRequest.getNewName()); jpaApp.setWebAppContext(updateApplicationRequest.getNewWebAppContext()); jpaApp.setGroup(jpaGroup); jpaApp.setSecure(updateApplicationRequest.isNewSecure()); jpaApp.setLoadBalanceAcrossServers(updateApplicationRequest.isNewLoadBalanceAcrossServers()); jpaApp.setUnpackWar(updateApplicationRequest.isUnpackWar()); try { return update(jpaApp); } catch (EntityExistsException eee) { LOGGER.error("Error updating application {} in group {}", jpaApp, jpaGroup, eee); throw new EntityExistsException("App already exists: " + updateApplicationRequest, eee); } } else { LOGGER.error("Application cannot be found {} attempting to update application", updateApplicationRequest); throw new BadRequestException(FaultType.INVALID_APPLICATION_NAME, "Application cannot be found: " + appId.getId()); } }
@Test(expected = EntityExistsException.class) public void testApplicationCrudServiceEEE() { CreateApplicationRequest request = new CreateApplicationRequest(expGroupId, textName, textContext, true, true, false); JpaApplication created = applicationCrudService.createApplication(request, jpaGroup); assertNotNull(created); try { JpaApplication duplicate = applicationCrudService.createApplication(request, jpaGroup); fail(duplicate.toString()); } catch (BadRequestException e) { assertEquals(FaultType.DUPLICATE_APPLICATION, e.getMessageResponseStatus()); throw e; } finally { try { applicationCrudService.removeApplication(Identifier.<Application>id(created.getId()) ); } catch (Exception x) { LOGGER.trace("Test tearDown", x); } } }
@Override public Response updateGroup(final JsonUpdateGroup anUpdatedGroup, final AuthenticatedUser aUser) { LOGGER.info("Update Group requested: {} by user {}", anUpdatedGroup, aUser.getUser().getId()); try { // TODO: Refactor adhoc conversion to process group name instead of Id. final Group group = groupService.getGroup(anUpdatedGroup.getId()); final JsonUpdateGroup updatedGroup = new JsonUpdateGroup(group.getId().getId().toString(), anUpdatedGroup.getName()); return ResponseBuilder.ok(groupService.updateGroup(updatedGroup.toUpdateGroupCommand(), aUser.getUser())); } catch (EntityExistsException eee) { LOGGER.error("Group Name already exists: {}", anUpdatedGroup.getName(), eee); return ResponseBuilder.notOk(Response.Status.INTERNAL_SERVER_ERROR, new FaultCodeException( FaultType.DUPLICATE_GROUP_NAME, eee.getMessage(), eee)); } }
@Override @Transactional public Group createGroup(final CreateGroupRequest createGroupRequest, final User aCreatingUser) { createGroupRequest.validate(); try { groupPersistenceService.getGroup(createGroupRequest.getGroupName()); String message = MessageFormat.format("Group Name already exists: {0} ", createGroupRequest.getGroupName()); LOGGER.error(message); throw new EntityExistsException(message); } catch (NotFoundException e) { LOGGER.debug("No group name conflict, ignoring not found exception for creating group ", e); } return groupPersistenceService.createGroup(createGroupRequest); }
@Override @Transactional public Group updateGroup(final UpdateGroupRequest anUpdateGroupRequest, final User anUpdatingUser) { anUpdateGroupRequest.validate(); Group orginalGroup = getGroup(anUpdateGroupRequest.getId()); try { if (!orginalGroup.getName().equalsIgnoreCase(anUpdateGroupRequest.getNewName()) && null != groupPersistenceService.getGroup(anUpdateGroupRequest.getNewName())) { String message = MessageFormat.format("Group Name already exists: {0}", anUpdateGroupRequest.getNewName()); LOGGER.error(message); throw new EntityExistsException(message); } } catch (NotFoundException e) { LOGGER.debug("No group name conflict, ignoring not found exception for creating group ", e); } return groupPersistenceService.updateGroup(anUpdateGroupRequest); }
public void createFolder(Folder pFolder) throws FolderAlreadyExistsException, CreationException{ try{ //the EntityExistsException is thrown only when flush occurs em.persist(pFolder); em.flush(); }catch(EntityExistsException pEEEx){ LOGGER.log(Level.FINEST,null,pEEEx); throw new FolderAlreadyExistsException(mLocale, pFolder); }catch(PersistenceException pPEx){ //EntityExistsException is case sensitive //whereas MySQL is not thus PersistenceException could be //thrown instead of EntityExistsException LOGGER.log(Level.FINEST,null,pPEx); throw new CreationException(mLocale); } }
public void createPathToPathLink(PathToPathLink pathToPathLink) throws CreationException, PathToPathLinkAlreadyExistsException { try { //the EntityExistsException is thrown only when flush occurs em.persist(pathToPathLink); em.flush(); } catch (EntityExistsException pEEEx) { LOGGER.log(Level.FINEST,null,pEEEx); throw new PathToPathLinkAlreadyExistsException(mLocale, pathToPathLink); } catch (PersistenceException pPEx) { LOGGER.log(Level.FINEST,null,pPEx); //EntityExistsException is case sensitive //whereas MySQL is not thus PersistenceException could be //thrown instead of EntityExistsException throw new CreationException(mLocale); } }
public void createDocM(DocumentMaster pDocumentMaster) throws DocumentMasterAlreadyExistsException, CreationException { try { //the EntityExistsException is thrown only when flush occurs em.persist(pDocumentMaster); em.flush(); } catch (EntityExistsException pEEEx) { LOGGER.log(Level.FINER,null,pEEEx); throw new DocumentMasterAlreadyExistsException(mLocale, pDocumentMaster); } catch (PersistenceException pPEx) { //EntityExistsException is case sensitive //whereas MySQL is not thus PersistenceException could be //thrown instead of EntityExistsException LOGGER.log(Level.FINER,null,pPEx); throw new CreationException(mLocale); } }
public void createQuery(Query query) throws CreationException, QueryAlreadyExistsException { try { QueryRule queryRule = query.getQueryRule(); if(queryRule != null){ persistQueryRules(queryRule); } QueryRule pathDataQueryRule = query.getPathDataQueryRule(); if (pathDataQueryRule != null) { persistQueryRules(pathDataQueryRule); } em.persist(query); em.flush(); persistContexts(query, query.getContexts()); } catch (EntityExistsException pEEEx) { LOGGER.log(Level.FINEST, null, pEEEx); throw new QueryAlreadyExistsException(mLocale, query); } catch (PersistenceException pPEx) { LOGGER.log(Level.FINEST, null, pPEx); throw new CreationException(mLocale); } }
public void createOrganization(Organization pOrganization) throws OrganizationAlreadyExistsException, CreationException { try { //the EntityExistsException is thrown only when flush occurs if (pOrganization.getName().trim().equals("")) throw new CreationException(mLocale); em.persist(pOrganization); em.flush(); } catch (EntityExistsException pEEEx) { throw new OrganizationAlreadyExistsException(mLocale, pOrganization); } catch (PersistenceException pPEx) { //EntityExistsException is case sensitive //whereas MySQL is not thus PersistenceException could be //thrown instead of EntityExistsException throw new CreationException(mLocale); } }
/** * {@inheritDoc} */ @Override public void persistValue(T value) { EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction transaction = entityManager.getTransaction(); transaction.begin(); try { entityManager.persist(value); transaction.commit(); } catch (PersistenceException e) { if (isEntityAlreadyExists(value)) { closeEntityManager(entityManager); throw new EntityExistsException(e.getCause()); } LOG.error("Cannot store {}. {}", value, e.getMessage()); } if (transaction.isActive() && transaction.getRollbackOnly()) { transaction.rollback(); } closeEntityManager(entityManager); }
void setClusterGuid(final ClusterVO cluster, final String guid) { cluster.setGuid(guid); try { _clusterDao.update(cluster.getId(), cluster); } catch (final EntityExistsException e) { final QueryBuilder<ClusterVO> sc = QueryBuilder.create(ClusterVO.class); sc.and(sc.entity().getGuid(), Op.EQ, guid); final List<ClusterVO> clusters = sc.list(); final ClusterVO clu = clusters.get(0); final List<HostVO> clusterHosts = _resourceMgr.listAllHostsInCluster(clu.getId()); if (clusterHosts == null || clusterHosts.size() == 0) { clu.setGuid(null); _clusterDao.update(clu.getId(), clu); _clusterDao.update(cluster.getId(), cluster); return; } throw e; } }
public <T extends WithId<T>> T create(final T entity) { Kind kind = entity.getKind(); Cache<String, T> cache = caches.getCache(kind.getModelName()); Optional<String> id = entity.getId(); String idVal; final T entityToCreate; if (!id.isPresent()) { idVal = KeyGenerator.createKey(); entityToCreate = entity.withId(idVal); } else { idVal = id.get(); if (cache.keySet().contains(idVal)) { throw new EntityExistsException("There already exists a " + kind + " with id " + idVal); } entityToCreate = entity; } this.<T, T>doWithDataAccessObject(kind.getModelClass(), d -> d.create(entityToCreate)); cache.put(idVal, entityToCreate); broadcast("created", kind.getModelName(), idVal); return entityToCreate; }
@Override public void putItemOrThrow(T item) { try { Expected[] expected; if ( null == _rkName ) { expected = new Expected[]{ new Expected(_hkName).notExist() }; } else { expected = new Expected[]{ new Expected(_hkName).notExist(), new Expected(_rkName).notExist() }; } maybeBackoff(false, () -> _putItem.putItem(_encryption.encrypt(toItem(item)), expected)); } catch ( ConditionalCheckFailedException ex ) { throw new EntityExistsException(ex); } }
public Object get(AjaxRequest ajaxRequest, EuropaRequestContext requestContext) { _permissionCheck.check(ajaxRequest.getOperation(), requestContext); String domain = requestContext.getOwnerDomain(); String name = ajaxRequest.getParam("name", true); Matcher m = pipelineNamePattern.matcher(name); if(!m.matches()) throw(new AjaxClientException("The Pipeline Name is invalid. It must match regex [a-zA-Z0-9_.-]", AjaxErrors.Codes.BadPipelineName, 400)); Pipeline pipeline = Pipeline.builder() .domain(domain) .name(name) .build(); try { _db.createPipeline(pipeline); } catch(EntityExistsException rbe) { throw(new AjaxClientException("A Pipeline with that name already exists.", AjaxErrors.Codes.PipelineAlreadyExists, 400)); } return pipeline; }
@Override public void addRoleToUserAndProject(String userid, String projectid, String roleid) { RoleAssignment roleAssignment = new RoleAssignment(); roleAssignment.setType(AssignmentType.USER_PROJECT); roleAssignment.setActorId(userid); roleAssignment.setTargetId(projectid); roleAssignment.setRoleId(roleid); roleAssignment.setInherited(false); try { roleAssignmentDao.persist(roleAssignment); } catch (EntityExistsException e) { String msg = MessageFormat.format(USER_ALREADY_HAS_ROLE, userid, roleid, projectid); logger.error(msg, e); throw Exceptions.ConflictException.getInstance(null, ROLE_GRANT, msg); // replace // KeyError } }
@Test public void testCreateWithId() { Exception exception = null; Greeting entity = new Greeting(); entity.setId(Long.MAX_VALUE); entity.setText("test"); try { service.create(entity); } catch (EntityExistsException e) { exception = e; } Assert.assertNotNull("failure - expected exception", exception); Assert.assertTrue("failure - expected EntityExistsException", exception instanceof EntityExistsException); }
@CachePut(value = Application.CACHE_GREETINGS, key = "#result.id") @Transactional @Override public Greeting create(final Greeting greeting) { logger.info("> create"); counterService.increment("method.invoked.greetingServiceBean.create"); // Ensure the entity object to be created does NOT exist in the // repository. Prevent the default behavior of save() which will update // an existing entity if the entity matching the supplied id exists. if (greeting.getId() != null) { logger.error("Attempted to create a Greeting, but id attribute was not null."); logger.info("< create"); throw new EntityExistsException( "Cannot create new Greeting with supplied id. The id attribute must be null to create an entity."); } final Greeting savedGreeting = greetingRepository.save(greeting); logger.info("< create"); return savedGreeting; }
@Test public void testCreateGreetingWithId() { Exception exception = null; final Greeting greeting = new Greeting(); greeting.setId(Long.MAX_VALUE); greeting.setText(VALUE_TEXT); try { greetingService.create(greeting); } catch (EntityExistsException eee) { exception = eee; } Assert.assertNotNull("failure - expected exception", exception); Assert.assertTrue("failure - expected EntityExistsException", exception instanceof EntityExistsException); }
@Override public void add(Vehicle vehicle) throws EntityExistsException { if (getByPlateNumber(vehicle.getNumber()).isPresent()) throw new EntityExistsException("The vehicle with plate number " + vehicle.getNumber() + " already exists in DB." ); vehicle.setId(getNextId()); vehicles.put(vehicle.getId(), vehicle); String number = vehicle.getNumber(); if(LOG.isEnabledFor(Level.TRACE)){ Optional<Vehicle> vehicleOrNull = getByPlateNumber(number); LOG.trace("Vehicle [{}] has GPS number : {}", number, vehicleOrNull.isPresent() ? vehicleOrNull.get().getGpsNumber(): "none"); } // LOG.trace("Vehicle [{}] has GPS number : {}", number, // getByPlateNumber(number).isPresent() ? getByPlateNumber(number).get().getGpsNumber(): "none"); }
@Test public void saveWithExistingName() { assertThrows(EntityExistsException.class, () -> { Report report = reportDAO.find("0062ea9c-924d-4ecf-9961-4492a8cc6d1b"); assertNotNull(report); String name = report.getName(); report = entityFactory.newEntity(Report.class); report.setName(name); report.setActive(true); report.setTemplate(reportTemplateDAO.find("sample")); reportDAO.save(report); reportDAO.flush(); }); }
@Test public void checkIdUniqueness() { assertNotNull(derSchemaDAO.find("cn")); PlainSchema schema = entityFactory.newEntity(PlainSchema.class); schema.setKey("cn"); schema.setType(AttrSchemaType.String); plainSchemaDAO.save(schema); try { plainSchemaDAO.flush(); fail("This should not happen"); } catch (Exception e) { assertTrue(e instanceof EntityExistsException); } }
void setClusterGuid(ClusterVO cluster, String guid) { cluster.setGuid(guid); try { _clusterDao.update(cluster.getId(), cluster); } catch (EntityExistsException e) { QueryBuilder<ClusterVO> sc = QueryBuilder.create(ClusterVO.class); sc.and(sc.entity().getGuid(), Op.EQ, guid); List<ClusterVO> clusters = sc.list(); ClusterVO clu = clusters.get(0); List<HostVO> clusterHosts = _resourceMgr.listAllHostsInCluster(clu.getId()); if (clusterHosts == null || clusterHosts.size() == 0) { clu.setGuid(null); _clusterDao.update(clu.getId(), clu); _clusterDao.update(cluster.getId(), cluster); return; } throw e; } }
@DB protected OvsTunnelInterfaceVO createInterfaceRecord(String ip, String netmask, String mac, long hostId, String label) { OvsTunnelInterfaceVO ti = null; try { ti = new OvsTunnelInterfaceVO(ip, netmask, mac, hostId, label); // TODO: Is locking really necessary here? OvsTunnelInterfaceVO lock = _tunnelInterfaceDao .acquireInLockTable(Long.valueOf(1)); if (lock == null) { s_logger.warn("Cannot lock table ovs_tunnel_account"); return null; } _tunnelInterfaceDao.persist(ti); _tunnelInterfaceDao.releaseFromLockTable(lock.getId()); } catch (EntityExistsException e) { s_logger.debug("A record for the interface for network " + label + " on host id " + hostId + " already exists"); } return ti; }
@DB protected OvsTunnelNetworkVO createTunnelRecord(long from, long to, long networkId, int key) { OvsTunnelNetworkVO ta = null; try { ta = new OvsTunnelNetworkVO(from, to, key, networkId); OvsTunnelNetworkVO lock = _tunnelNetworkDao.acquireInLockTable(Long.valueOf(1)); if (lock == null) { s_logger.warn("Cannot lock table ovs_tunnel_account"); return null; } _tunnelNetworkDao.persist(ta); _tunnelNetworkDao.releaseFromLockTable(lock.getId()); } catch (EntityExistsException e) { s_logger.debug("A record for the tunnel from " + from + " to " + to + " already exists"); } return ta; }
@Override public CiscoAsa1000vDevice addCiscoAsa1000vResource(AddCiscoAsa1000vResourceCmd cmd) { Long physicalNetworkId = cmd.getPhysicalNetworkId(); CiscoAsa1000vDevice ciscoAsa1000vResource = null; PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId); if (physicalNetwork == null) { throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId); } ciscoAsa1000vResource = new CiscoAsa1000vDeviceVO(physicalNetworkId, cmd.getManagementIp().trim(), cmd.getInPortProfile(), cmd.getClusterId()); try { _ciscoAsa1000vDao.persist((CiscoAsa1000vDeviceVO)ciscoAsa1000vResource); } catch (EntityExistsException e) { throw new InvalidParameterValueException("An ASA 1000v appliance already exists with same configuration"); } return ciscoAsa1000vResource; }
@Override public void execute() throws ServerApiException, ConcurrentOperationException, EntityExistsException { SuccessResponse response = new SuccessResponse(); try { boolean result = _netsclarLbService.deleteServicePackageOffering(this); if (response != null && result) { response.setDisplayText("Deleted Successfully"); response.setSuccess(result); response.setResponseName(getCommandName()); this.setResponseObject(response); } } catch (CloudRuntimeException runtimeExcp) { response.setDisplayText(runtimeExcp.getMessage()); response.setSuccess(false); response.setResponseName(getCommandName()); this.setResponseObject(response); return; } catch (Exception e) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Service Package due to internal error."); } }
@Override public void execute() throws ServerApiException, ConcurrentOperationException, EntityExistsException { SuccessResponse response = new SuccessResponse(); try { boolean result = _netsclarLbService.deleteNetscalerControlCenter(this); if (response != null && result) { response.setDisplayText("Netscaler Control Center Deleted Successfully"); response.setSuccess(result); response.setResponseName(getCommandName()); setResponseObject(response); } } catch (CloudRuntimeException runtimeExcp) { response.setDisplayText(runtimeExcp.getMessage()); response.setSuccess(false); response.setResponseName(getCommandName()); setResponseObject(response); return; } catch (Exception e) { e.printStackTrace(); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } }
/** * This inserts a new entity into App Engine datastore. If the entity already * exists in the datastore, an exception is thrown. * It uses HTTP POST method. * * @param stopWatchState the entity to be inserted. * @return The inserted entity. */ @ApiMethod(name = "insertStopWatchState") public StopWatchState insertStopWatchState(StopWatchState stopWatchState) { EntityManager mgr = getEntityManager(); try { if (containsStopWatchState(stopWatchState)) { throw new EntityExistsException("Object already exists"); } mgr.persist(stopWatchState); // Send to GCM Sender sender = new Sender(API_KEY); } finally { mgr.close(); } return stopWatchState; }
/** * The create inserts a new row if none is present and then returns the result populated with what data the request provided. * @param piSerialId * @param ipAddress * @return * @throws HomePiAppException */ public PiProfile createPiProfile(String piSerialId, String ipAddress, String userName) throws HomePiAppException { if(StringUtil.isNullOrEmpty(piSerialId)){ throw new HomePiAppException(Status.BAD_REQUEST, "Invalid Pi Serial ID."); } try{ PiProfile piProfile = new PiProfile(); piProfile.setPiSerialId(piSerialId); piProfile.setCreateTime(new DateTime()); piProfile.setIpAddress(ipAddress); piProfile.setName("PI-"+piSerialId); //sets default name piProfile.setUserId(getUid(userName)); piProfileDao.save(piProfile); //Add apiKey to the entry. piProfileDao.updateUUID(piProfile); return piProfileDao.findOne(piProfile.getPiId()); } catch(EntityExistsException eee){ throw new HomePiAppException(Status.BAD_REQUEST, piSerialId + ": This PI has already been registered"); } catch(Exception e){ throw new HomePiAppException(Status.BAD_REQUEST, e); } }
@Test(expected = ConcurrentModificationException.class) public void mapEJBExceptions() throws Exception { mapper.mapEJBExceptions(new InvocationContextStub() { public Object proceed() throws Exception { throw new EJBException(new EntityExistsException()); } }); }
private boolean canMapToConcurrentModificationException( PersistenceException pe) { if (pe instanceof EntityExistsException || pe instanceof OptimisticLockException) { return true; } return false; }
@Override public JpaGroup createGroup(CreateGroupRequest createGroupRequest) { final JpaGroup jpaGroup = new JpaGroup(); jpaGroup.setName(createGroupRequest.getGroupName()); try { return create(jpaGroup); } catch (final EntityExistsException eee) { LOGGER.error("Error creating group {}", createGroupRequest, eee); throw new EntityExistsException("Group Name already exists: " + createGroupRequest, eee); } }