/** * Check schema. * * @param schemaDto the schema dto * @param file the file * @throws NotFoundException the control service exception */ private void checkSchema(VersionDto schemaDto, RecordFiles file) throws NotFoundException { if (schemaDto == null) { throw new NotFoundException("Schema " + file + " not found!"); } }
/** * This method validates <code>Object</code> object. If object is null than throw * <code>IncorrectParameterException</code> exception * * @param obj the obj * @param errorMessage the error message for exception */ public static void validateNotNull(Object obj, String errorMessage) { if (obj == null) { throw new IncorrectParameterException(errorMessage); } }
@Override public void removeEndpointRegistrationById(String registrationId) throws EndpointRegistrationServiceException { try { Validate.notBlank(registrationId, "Invalid registration ID provided!"); this.endpointRegistrationDao.removeById(registrationId); } catch (Exception cause) { LOG.error("An unexpected exception occured while removing endpoint registration!", cause); throw new EndpointRegistrationServiceException(cause); } } }
private ServerProfileSchemaDto getServerProfileSchema(String applicationId, Integer serverProfileVersion) throws Exception { ServerProfileSchemaDto serverProfileSchema = this.controlService.getServerProfileSchemaByApplicationIdAndVersion( applicationId, serverProfileVersion); if (serverProfileSchema == null) { throw new NotFoundException("No server-side endpoint profile schema found!"); } return serverProfileSchema; }
/** * This method validates <code>Object</code> object. If object is not null than throw * <code>IncorrectParameterException</code> exception * * @param obj the obj * @param errorMessage the error message for exception */ public static void validateNull(Object obj, String errorMessage) { if (obj != null) { throw new IncorrectParameterException(errorMessage); } }
@Override public void removeEndpointRegistrationByEndpointId(String endpointId) throws EndpointRegistrationServiceException { try { Validate.notBlank(endpointId, "Invalid endpoint ID provided!"); this.endpointRegistrationDao.removeByEndpointId(endpointId); } catch (Exception cause) { LOG.error("An unexpected exception occured while removing endpoint registration!", cause); throw new EndpointRegistrationServiceException(cause); } }
@Override public CTLSchemaDto getCtlSchemaById(String schemaId) throws ControlServiceException { CTLSchemaDto ctlSchemaDto = ctlService.findCtlSchemaById(schemaId); if (ctlSchemaDto == null) { LOG.error("CTL schema with Id [{}] not found!", schemaId); throw new NotFoundException("CTL schema not found!"); } return ctlSchemaDto; }
/** * This method validate <code>String</code> string. If string is invalid than throw * <code>IncorrectParameterException</code> exception * * @param id the id * @param errorMessage the error message for exception */ public static void validateString(String id, String errorMessage) { if (id == null || id.isEmpty()) { throw new IncorrectParameterException(errorMessage); } }
@Override public EndpointSpecificConfigurationDto findEndpointSpecificConfiguration(byte[] endpointKeyHash, Integer confSchemaVersion) { Optional<EndpointSpecificConfigurationDto> result; if (confSchemaVersion == null) { result = endpointSpecificConfigurationService.findActiveConfigurationByEndpointKeyHash(endpointKeyHash); } else { result = endpointSpecificConfigurationService.findByEndpointKeyHashAndConfSchemaVersion(endpointKeyHash, confSchemaVersion); } return result.orElseThrow(() -> new NotFoundException("Endpoint specific configuration not found")); }
/** * @param id the id. * @param errorMessage the error message for exception */ public static void validateSqlId(String id, String errorMessage) { try { Long.valueOf(id); } catch (NumberFormatException ex) { throw new IncorrectParameterException(errorMessage, ex); } }
@Override public EndpointSpecificConfigurationDto deleteEndpointSpecificConfiguration(byte[] endpointKeyHash, Integer confSchemaVersion) { Optional<EndpointSpecificConfigurationDto> result; if (confSchemaVersion == null) { result = endpointSpecificConfigurationService.deleteActiveConfigurationByEndpointKeyHash(endpointKeyHash); } else { result = endpointSpecificConfigurationService.deleteByEndpointKeyHashAndConfSchemaVersion(endpointKeyHash, confSchemaVersion); } EndpointSpecificConfigurationDto configuration = result .orElseThrow(() -> new NotFoundException("Endpoint specific configuration not found")); sendEndpointConfigurationRefreshMessage(configuration); return configuration; }
private void validateFilterSchemaIds(String endpointProfileSchemaId, String serverProfileSchemaId) { if (isBlank(endpointProfileSchemaId) && isBlank(serverProfileSchemaId)) { throw new IncorrectParameterException("Both profile schema ids can't be empty"); } }
/** * This method validate <code>byte</code> array hash. If hash is invalid than throw * <code>IncorrectParameterException</code> exception * * @param hash the hash * @param errorMessage the error message for exception */ public static void validateHash(byte[] hash, String errorMessage) { if (!isValidHash(hash)) { throw new IncorrectParameterException(errorMessage); } }
/** * This method validate <code>HasId</code> object. If object is invalid than throw * <code>IncorrectParameterException</code> exception * * @param hasId the hash id * @param errorMessage the error message for exception */ public static void validateObject(HasId hasId, String errorMessage) { if (!isValidObject(hasId)) { throw new IncorrectParameterException(errorMessage); } }
/** * This method validate <code>String</code> id. If id is invalid than throw * <code>IncorrectParameterException</code> exception * * @param id the id * @param errorMessage the error message for exception */ public static void validateId(String id, String errorMessage) { if (!isValidId(id)) { throw new IncorrectParameterException(errorMessage); } }
/** * This method validate <code>HasId</code> object. If object is invalid than throw * <code>IncorrectParameterException</code> exception * * @param hasId the hash id * @param errorMessage the error message for exceptio */ public static void validateSqlObject(HasId hasId, String errorMessage) { if (!isValidSqlObject(hasId)) { throw new IncorrectParameterException(errorMessage); } } }
private void validateFilter(ProfileFilterDto dto) { if (dto == null) { throw new IncorrectParameterException("Can't save profile filter. Incorrect object."); } if (dto.getEndpointProfileSchemaId() == null && dto.getServerProfileSchemaId() == null) { throw new IncorrectParameterException( "Profile Filter object invalid. Both schemas are empty."); } if (StringUtils.isBlank(dto.getEndpointGroupId())) { throw new IncorrectParameterException( "Profile Filter object invalid. Endpoint Group id invalid:" + dto.getEndpointGroupId()); } } }
@Override public CTLSchemaDto findCtlSchemaByFqnAndVerAndTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId) { if (isBlank(fqn) || version == null) { throw new IncorrectParameterException("Incorrect parameters for ctl schema request."); } LOG.debug("Find ctl schema by fqn {} version {}, tenant id {} and application id {}", fqn, version, tenantId, applicationId); return DaoUtil.getDto(ctlSchemaDao.findByFqnAndVerAndTenantIdAndApplicationId(fqn, version, tenantId, applicationId)); }
@Override public List<EventClassFamilyDto> findEventClassFamiliesByTenantId( String tenantId) { List<EventClassFamilyDto> eventClassFamilies; if (isValidSqlId(tenantId)) { LOG.debug("Find event class families by tenant id [{}]", tenantId); eventClassFamilies = convertDtoList(eventClassFamilyDao.findByTenantId(tenantId)); } else { throw new IncorrectParameterException("Incorrect tenant id: " + tenantId); } return eventClassFamilies; }
private void validateNotificationSchemaObject(NotificationSchemaDto dto) { validateObject(dto, "Invalid notification schema object"); if (isBlank(dto.getApplicationId()) && !isValidId(dto.getApplicationId()) || dto.getType() == null) { throw new IncorrectParameterException( "Invalid notification schema object. Check type or applicationId."); } }