/** * Returns the {@link AlertingDefinition} for the given id. * * @param id * the identifier of the {@link AlertingDefinition} * @return {@link AlertingDefinition} of the given id * @throws BusinessException * if no {@link AlertingDefinition} exists for the given id */ public AlertingDefinition getAlertingDefinition(String id) throws BusinessException { AlertingDefinition alertingDefinition = existingAlertingDefinitions.get(id); if (null == alertingDefinition) { throw new BusinessException("Load alerting definition with the id=" + id + ".", AlertErrorCodeEnum.ALERTING_DEFINITION_DOES_NOT_EXIST); } return alertingDefinition; }
/** * Test the Business exception. */ @Test public void businessException() throws SerializationException { BusinessException businessException = new BusinessException("Message", StorageErrorCodeEnum.CAN_NOT_START_RECORDING); businessException.printStackTrace(); BusinessException deserialized = serializeBackAndForth(businessException); assertThat(deserialized, is(instanceOf(BusinessException.class))); assertThat(deserialized.getMessage(), is(equalTo(businessException.getMessage()))); assertThat(deserialized.getStackTrace(), is(equalTo(businessException.getStackTrace()))); assertThat(deserialized.getActionPerformed(), is(equalTo(businessException.getActionPerformed()))); assertThat(deserialized.getErrorCode(), is(equalTo(businessException.getErrorCode()))); }
e.setServiceMethodSignature(jp.getSignature().toString());
if (null != exception.getActionPerformed()) { mainMessage.append("An exception occurred while executing the action <span color=\"headingColor\">" + exception.getActionPerformed() + "</span><br/><br/>"); if (null != exception.getServiceMethodSignature()) { mainMessage.append("The exception occurred while invoking the service method <span color=\"headingColor\">" + exception.getServiceMethodSignature() + "</span><br/><br/>"); mainMessageFormText.setColor("headingColor", toolkit.getColors().getColor(IFormColors.TITLE)); IErrorCode errorCode = exception.getErrorCode();
/** * {@inheritDoc} */ @Override public void create() { super.create(); this.setTitle(dialogTitle); this.setTitleImage(InspectIT.getDefault().getImage(InspectITImages.IMG_WIZBAN_ERROR)); if (null != exception.getErrorCode()) { this.setMessage(exception.getErrorCode().getName()); } }
/** * Registers the platform at the CMR. * * @throws ServerUnavailableException * If the sending wasn't successful in any way, a {@link ServerUnavailableException} * exception is thrown. * @throws RegistrationException * This exception is thrown when a problem with the registration process appears. * @throws StorageException * If setting configuration to the {@link #configurationStorage} fails. */ private void register() throws ServerUnavailableException, RegistrationException, StorageException { try { AgentConfig agentConfiguration = connection.register(configurationStorage.getAgentName(), versionService.getVersionAsString()); platformId = agentConfiguration.getPlatformId(); configurationStorage.setAgentConfiguration(agentConfiguration); if (log.isDebugEnabled()) { log.debug("Received platform ID: " + platformId); } } catch (BusinessException exception) { log.error("The agent was not able to get configuration from the server. " + exception.getMessage()); throw new BeanInitializationException("The agent was not able to get configuration from the server.", exception); } }
/** * Constructor that allows definition of the action. * * @param actionPerformed * Action being performed when exception occurred. * @param errorCode * Error code describing the exception. */ public BusinessException(String actionPerformed, IErrorCode errorCode) { super(generateMessage(actionPerformed, errorCode)); this.actionPerformed = actionPerformed; this.errorCode = errorCode; }
if (executionException.getCause() instanceof BusinessException) { BusinessException businessException = (BusinessException) executionException.getCause(); if (AgentManagementErrorCodeEnum.AGENT_DOES_NOT_EXIST.equals(businessException.getErrorCode())) { agentStatisticsLogger.noClassCacheAvailable(); return null;
/** * Returns the profile with the given id. * * @param id * Id of profile. * @return {@link Profile} * @throws BusinessException * If profile with given id does not exist. */ public Profile getProfile(String id) throws BusinessException { Profile profile = existingProfiles.get(id); if (null == profile) { throw new BusinessException("Load profile with the id=" + id + ".", ConfigurationInterfaceErrorCodeEnum.PROFILE_DOES_NOT_EXIST); } return profile; }
if (AgentManagementErrorCodeEnum.AGENT_DOES_NOT_EXIST.equals(e.getErrorCode())) { agentStatisticsLogger.noClassCacheAvailable(); } else {
@Test(expectedExceptions = { BusinessException.class }) public void businessException() throws Throwable { String methodSignature = "methodSignature"; BusinessException businessException = mock(BusinessException.class); when(jp.proceed()).thenThrow(businessException); when(signature.toString()).thenReturn(methodSignature); try { interceptor.logServiceException(jp); } finally { verify(jp, times(1)).proceed(); verify(businessException, times(1)).setServiceMethodSignature(methodSignature); } }
/** * Returns the environment with the given id. * * @param id * Id of environment. * @return {@link Environment} * @throws BusinessException * If environment with given id does not exist. */ public Environment getEnvironment(String id) throws BusinessException { Environment environment = existingEnvironments.get(id); if (null == environment) { throw new BusinessException("Load environemnt with the id=" + id + ".", ConfigurationInterfaceErrorCodeEnum.ENVIRONMENT_DOES_NOT_EXIST); } return environment; }
/** * {@inheritDoc} */ @Override public PlatformIdent getCompleteAgent(long id) throws BusinessException { for (PlatformIdent platformIdent : agents) { if (platformIdent.getId().longValue() == id) { return platformIdent; } } throw new BusinessException("Load the agent with the ID=" + id + ".", AgentManagementErrorCodeEnum.AGENT_DOES_NOT_EXIST); }
/** * Moves the {@link BusinessTransactionDefinition} to a different position specified by the * index parameter. * * @param businessTransactionDefinition * {@link BusinessTransactionDefinition} to move * @param index * position to move the {@link BusinessTransactionDefinition} to * @throws BusinessException * If the moving the {@link BusinessTransactionDefinition} fails. */ public void moveBusinessTransactionDefinition(BusinessTransactionDefinition businessTransactionDefinition, int index) throws BusinessException { if ((index < 0) || (index >= businessTransactionDefinitions.size())) { throw new BusinessException("Moving business transaction to index " + index + ".", BusinessContextErrorCodeEnum.INVALID_MOVE_OPRATION); } int currentIndex = businessTransactionDefinitions.indexOf(businessTransactionDefinition); if (currentIndex < 0) { throw new BusinessException("Moving business transaction to index " + index + ".", BusinessContextErrorCodeEnum.UNKNOWN_BUSINESS_TRANSACTION); } if (index != currentIndex) { BusinessTransactionDefinition definitionToMove = businessTransactionDefinitions.remove(currentIndex); businessTransactionDefinitions.add(index, definitionToMove); } }
/** * {@inheritDoc} */ @Override public void removeLabelType(AbstractStorageLabelType<?> labelType) throws BusinessException { if (getAllLabelsForType(labelType).isEmpty()) { JpaUtil.delete(entityManager, labelType); } else { throw new BusinessException("Delete label type " + labelType.getClass().getSimpleName() + ".", StorageErrorCodeEnum.LABEL_TYPE_CAN_NOT_BE_DELETED); } }
/** * Retrieves the {@link ApplicationDefinition} with the given identifier. * * @param id * unique id identifying the application definition to retrieve * @return Return the {@link ApplicationDefinition} with the given id, or null if no application * definition with the passed id could be found. * @throws BusinessException * if an application with the given id does not exist. */ public ApplicationDefinition getApplicationDefinition(int id) throws BusinessException { if (id == ApplicationDefinition.DEFAULT_ID) { return ApplicationDefinition.DEFAULT_APPLICATION_DEFINITION; } for (ApplicationDefinition appDef : applicationDefinitions) { if (appDef.getId() == id) { return appDef; } } throw new BusinessException("Retrieve application with id '" + id + "'.", BusinessContextErrorCodeEnum.UNKNOWN_APPLICATION); }
/** * Retrieves the {@link BusinessTransactionDefinition} with the given identifier. * * @param id * unique id identifying the business transaction to retrieve * @return Return the {@link BusinessTransactionDefinition} with the given id, or null if no * {@link BusinessTransactionDefinition} with the passed id could be found. * * @throws BusinessException * if no {@link BusinessTransactionDefinition} with the given identifier exists. */ public BusinessTransactionDefinition getBusinessTransactionDefinition(int id) throws BusinessException { if (id == BusinessTransactionDefinition.DEFAULT_ID) { return BusinessTransactionDefinition.DEFAULT_BUSINESS_TRANSACTION_DEFINITION; } for (BusinessTransactionDefinition businessTxDef : businessTransactionDefinitions) { if (businessTxDef.getId() == id) { return businessTxDef; } } throw new BusinessException("Retrieve business transaction with id '" + id + "'.", BusinessContextErrorCodeEnum.UNKNOWN_BUSINESS_TRANSACTION); }
/** * {@inheritDoc} * * @throws BusinessException */ @Override @MethodLog public void unregisterPlatformIdent(long platformId) throws BusinessException { log.info("Trying to unregister the Agent with the ID " + platformId); boolean unregistered = agentStatusDataProvider.registerDisconnected(platformId); if (unregistered) { log.info("The Agent with the ID " + platformId + " has been successfully unregistered."); } else { log.warn("No registered agent with given ID exists. Unregistration is aborted."); throw new BusinessException("Unregister the agent with ID " + platformId + ".", AgentManagementErrorCodeEnum.AGENT_DOES_NOT_EXIST); } }
/** * Returns the local cached object that represent the {@link StorageData}. * * @param storageData * Template. * @return Local object. * @throws BusinessException * If local object can not be found. */ private StorageData getLocalStorageDataObject(StorageData storageData) throws BusinessException { for (StorageData existing : existingStoragesSet) { if (existing.getId().equals(storageData.getId())) { return existing; } } throw new BusinessException("Find storage " + storageData + ".", StorageErrorCodeEnum.STORAGE_DOES_NOT_EXIST); }
/** * Adds business transaction definition to the application definition. Inserts it to the list * before the element with the passed index. * * @param businessTransactionDefinition * {@link BusinessTransactionDefinition} instance to add * @param insertBeforeIndex * insert before this index * @throws BusinessException * If the application definition already contains a business transaction with same * identifier or the insertBeforeIndex is not valid. */ public void addBusinessTransactionDefinition(BusinessTransactionDefinition businessTransactionDefinition, int insertBeforeIndex) throws BusinessException { if (businessTransactionDefinition == null) { throw new BusinessException("Adding business transaction 'null'.", BusinessContextErrorCodeEnum.UNKNOWN_BUSINESS_TRANSACTION); } else if (businessTransactionDefinitions.contains(businessTransactionDefinition)) { throw new BusinessException( "Adding business transaction " + businessTransactionDefinition.getBusinessTransactionDefinitionName() + " with id " + businessTransactionDefinition.getId() + ".", BusinessContextErrorCodeEnum.DUPLICATE_ITEM); } else if ((insertBeforeIndex < 0) || (insertBeforeIndex > businessTransactionDefinitions.size())) { throw new BusinessException("Adding business transaction " + businessTransactionDefinition.getBusinessTransactionDefinitionName() + " with id " + businessTransactionDefinition.getId() + " at index " + insertBeforeIndex + ".", BusinessContextErrorCodeEnum.INVALID_MOVE_OPRATION); } else { businessTransactionDefinitions.add(insertBeforeIndex, businessTransactionDefinition); } }