/** * Validate all arguments. If at least one argument is either null or empty an exception is thrown */ public static void validateNotNullOrEmptyChecked(String... arguments) throws ValidationException { for (String argument : arguments) { if (argument == null || argument.isEmpty()) { throw new ValidationException("Argument must not be null or empty"); } } }
@Test public void deleteFunctionWhenOverwrittenByFunctionShouldAddOverwritingFunctionToException() throws NotFoundException { // given functionA_ID_4.overwrite(functionA_ID_3); functionA_ID_3.setResource(resource); assertTrue(functionA_ID_3.isOverwrittenBySubTypeOrResourceFunction()); when(functionRepositoryMock.find(ID_3)).thenReturn(functionA_ID_3); // when try { functionsBoundary.deleteFunction(functionA_ID_3.getId()); } catch (ValidationException e) { assertTrue(e.hasCausingObject()); assertEquals(functionA_ID_4, e.getCausingObject()); } }
@HasPermission(permission = Permission.MANAGE_DEPLOYMENT_PARAMETER, action = CREATE) public void createDeployParameterKey(String deployParameterKeyName) throws ValidationException { if (deployParameterKeyName != null && !deployParameterKeyName.trim().isEmpty()) { Key newKey = new Key(deployParameterKeyName.trim()); if (keyRepository.findFirstKeyByName(newKey.getName()) != null) { throw new ValidationException("a key with same name exists", deployParameterKeyName); } keyRepository.createDeployParameterKey(newKey); } else { throw new ValidationException("invalid empty name", deployParameterKeyName); } } }
@HasPermission(permission = Permission.MANAGE_DEPLOYMENT_PARAMETER, action = UPDATE) public void changeDeployParameterKey(Integer keyToDeleteId, String changedName) throws ValidationException { if (changedName != null && !changedName.trim().isEmpty()) { Key attachedKeyToChange = keyRepository.find(Objects.requireNonNull(keyToDeleteId, "Must not be null")); attachedKeyToChange.setName(changedName); keyRepository.merge(attachedKeyToChange); } else { throw new ValidationException("invalid empty name", changedName); } }
protected void verifyDefaultPropertyCanBeSet(ResourceEditProperty property, ContextEntity context) throws ValidationException { if (isSameValue(property.getDefaultValue(), property.getPropertyValue())) { if (context.isGlobal()) { // do not overwrite property value throw new ValidationException("The default value of property \"" + property.getPropertyDisplayName() + "\" can not be set on global context"); } if (property.getParent() == null && property.getOriginalValue() == null) { throw new ValidationException("The default value of property \"" + property.getPropertyDisplayName() + "\" can not be set unless it overwrites a value defined on a parent context"); } } }
/** * Creates a new Function for a ResourceType with miks */ public AmwFunctionEntity createNewResourceTypeFunction(AmwFunctionEntity amwFunction, Integer resourceTypeId, Set<String> functionMikNames) throws ValidationException, AMWException { ResourceTypeEntity resourceType = resourceTypeRepository.find(resourceTypeId); permissionBoundary.checkPermissionAndFireException(Permission.RESOURCETYPE_AMWFUNCTION, null, Action.CREATE, null, resourceType, "missing Permission to create ResourceType functions"); // search for already existing functions with this name on functiontree List<AmwFunctionEntity> allFunctionsWithName = functionService.findFunctionsByNameInNamespace(resourceType, amwFunction.getName()); if (allFunctionsWithName.isEmpty()) { amwFunction.setResourceType(resourceType); freemarkerValidator.validateFreemarkerSyntax(amwFunction.getDecoratedImplementation()); functionService.saveFunctionWithMiks(amwFunction, functionMikNames); } else { throw new ValidationException("Function name already in use", allFunctionsWithName.get(0)); } return amwFunction; }
/** * Creates a new Function for a Resource with miks */ public AmwFunctionEntity createNewResourceFunction(AmwFunctionEntity amwFunction, Integer resourceId, Set<String> functionMikNames) throws ValidationException, AMWException { ResourceEntity resource = resourceRepository.find(resourceId); permissionBoundary.checkPermissionAndFireException(Permission.RESOURCE_AMWFUNCTION, null, Action.CREATE, resource.getResourceGroup(), resource.getResourceType(), "missing Permission to create Resource functions"); // search for already existing functions with this name on functiontree List<AmwFunctionEntity> allFunctionsWithName = functionService.findFunctionsByNameInNamespace(resource, amwFunction.getName()); if (allFunctionsWithName.isEmpty()) { amwFunction.setResource(resource); freemarkerValidator.validateFreemarkerSyntax(amwFunction.getDecoratedImplementation()); functionService.saveFunctionWithMiks(amwFunction, functionMikNames); } else { throw new ValidationException("Function name already in use", allFunctionsWithName.get(0)); } return amwFunction; }
public void deleteFunction(Integer selectedFunctionIdToBeRemoved) throws ValidationException, NotFoundException { Objects.requireNonNull(selectedFunctionIdToBeRemoved, "Resource Type Entity must not be null"); AmwFunctionEntity functionToDelete = functionRepository.find(selectedFunctionIdToBeRemoved); if (functionToDelete == null) { throw new NotFoundException("No function entity found for id " + selectedFunctionIdToBeRemoved); } if (functionToDelete.getResource() == null && functionToDelete.getResourceType() != null) { permissionBoundary.checkPermissionAndFireException(Permission.RESOURCETYPE_AMWFUNCTION, null, Action.DELETE, null, functionToDelete.getResourceType(), "missing Permission to delete ResourceType functions"); } else { permissionBoundary.checkPermissionAndFireException(Permission.RESOURCE_AMWFUNCTION, null, Action.DELETE, functionToDelete.getResource().getResourceGroup(), null, "missing Permission to delete Resource functions"); } if (!functionToDelete.isOverwrittenBySubTypeOrResourceFunction()) { functionService.deleteFunction(functionToDelete); } else { throw new ValidationException("Can not delete function because it is overwritten by at least one sub resource type or resource function", functionToDelete.getOverwritingChildFunction().iterator().next()); } }
throw new ValidationException("Resource '" + slaveGroupName + "' is already provided by another ResourceGroup");
public void setPropertyValue(ContextDependency<?> resourceContext, Integer propertyDescriptorId, String unobfuscatedValue) throws ValidationException { PropertyEntity p = resourceContext.getPropertyForDescriptor(propertyDescriptorId); if (p == null) { PropertyDescriptorEntity propertyDescriptor = entityManager.find(PropertyDescriptorEntity.class, propertyDescriptorId); p = new PropertyEntity(); p.setDescriptor(propertyDescriptor); p.setOwningResource(resourceContext); resourceContext.addProperty(p); } if (!propertyValidationService.canPropertyValueBeSetOnContext(p.getDescriptor(), resourceContext)) { throw new ValidationException("The property " + p.getDescriptor() + " can not be set on context " + resourceContext.getContext()); } p.setValue(unobfuscatedValue); }