use of alien4cloud.exception.InvalidArgumentException in project alien4cloud by alien4cloud.
the class CsarGitRepositoryService method create.
/**
* Create a CsarGitRepository in the system to store its informations
*
* @param repositoryUrl The unique Git url of the CsarGitRepository
* @param username The username of the user
* @param password The password of the user
* @param importLocations Locations where Csar's files are store
* @param isStoredLocally The state of the the CsarGitRepository
* @return The auto-generated id of the CsarGitRepository object
*/
public String create(String repositoryUrl, String username, String password, List<CsarGitCheckoutLocation> importLocations, boolean isStoredLocally) {
validatesRepositoryUrl(repositoryUrl);
failIfExists(repositoryUrl);
if (importLocations.isEmpty()) {
throw new InvalidArgumentException("Import locations cannot be empty.");
}
// create it
CsarGitRepository csarGit = new CsarGitRepository();
csarGit.setId(UUID.randomUUID().toString());
csarGit.setRepositoryUrl(repositoryUrl);
csarGit.setUsername(username);
csarGit.setPassword(password);
csarGit.setImportLocations(importLocations);
csarGit.setStoredLocally(isStoredLocally);
alienDAO.save(csarGit);
return csarGit.getId();
}
use of alien4cloud.exception.InvalidArgumentException in project alien4cloud by alien4cloud.
the class NodeMatcherService method match.
public Map<String, List<LocationResourceTemplate>> match(Map<String, NodeType> nodesTypes, Map<String, NodeTemplate> nodesToMatch, Location location, String environmentId) {
Map<String, List<LocationResourceTemplate>> matchingResult = Maps.newHashMap();
// fetch location resources
LocationResources locationResources = locationResourceService.getLocationResources(location);
// Authorization filtering of location resources
filterOnAuthorization(locationResources.getNodeTemplates(), environmentId);
// fetch service resources
List<ServiceResource> services = serviceResourceService.searchByLocation(location.getId());
// self filtering: remove managed service linked to this location
filterSelfManagedService(services, environmentId);
// Authorization filtering of location resources
filterOnAuthorization(services, environmentId);
// from serviceResource to locationResource
populateLocationResourcesWithServiceResource(locationResources, services, location.getId());
Map<String, MatchingConfiguration> matchingConfigurations = locationMatchingConfigurationService.getMatchingConfiguration(location);
Set<String> typesManagedByLocation = Sets.newHashSet();
for (NodeType nodeType : locationResources.getNodeTypes().values()) {
typesManagedByLocation.add(nodeType.getElementId());
typesManagedByLocation.addAll(nodeType.getDerivedFrom());
}
INodeMatcherPlugin nodeMatcherPlugin = getNodeMatcherPlugin();
for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodesToMatch.entrySet()) {
String nodeTemplateId = nodeTemplateEntry.getKey();
NodeTemplate nodeTemplate = nodeTemplateEntry.getValue();
if (typesManagedByLocation.contains(nodeTemplate.getType())) {
NodeType nodeTemplateType = nodesTypes.get(nodeTemplate.getType());
if (nodeTemplateType == null) {
throw new InvalidArgumentException("The given node types map must contain the type of the node template");
}
matchingResult.put(nodeTemplateId, nodeMatcherPlugin.matchNode(nodeTemplate, nodeTemplateType, locationResources, matchingConfigurations));
}
}
return matchingResult;
}
use of alien4cloud.exception.InvalidArgumentException in project alien4cloud by alien4cloud.
the class GroupService method updateGroup.
public void updateGroup(String groupId, UpdateGroupRequest groupUpdateRequest) {
Group group = retrieveGroup(groupId);
String currentGroupName = group.getName();
ReflectionUtil.mergeObject(groupUpdateRequest, group);
if (group.getName() == null || group.getName().isEmpty()) {
throw new InvalidArgumentException("Group's name cannot be set to null or empty");
}
// Check with precedent value
if (!currentGroupName.equals(group.getName())) {
// If group name has changed, must check unicity
checkGroupNameUniqueness(group.getName());
}
alienGroupDao.save(group);
}
use of alien4cloud.exception.InvalidArgumentException in project alien4cloud by alien4cloud.
the class AuditController method enableMethodAudit.
private void enableMethodAudit(Map<Method, Boolean> auditedMethodsMap, AuditedMethod method) {
if (method.getMethod() == null) {
throw new InvalidArgumentException("Method's path or http method is null");
}
Method auditedMethodKey = new Method(method.getSignature(), method.getMethod(), method.getCategory(), method.getAction(), method.getBodyHiddenFields());
if (!auditedMethodsMap.containsKey(auditedMethodKey)) {
throw new NotFoundException("Method " + method + " does not exist ");
}
auditedMethodsMap.put(auditedMethodKey, method.isEnabled());
}
use of alien4cloud.exception.InvalidArgumentException in project alien4cloud by alien4cloud.
the class ReflectionUtil method mergeObject.
/**
* Merge object from an object to another. Failsafe : resist to invalid property.
*
* @param from source of the update
* @param to target of the update
* @param ignoreNullValue indicate if we should merge null value
* @param ignores properties names that should be ignored
*/
public static void mergeObject(Object from, Object to, boolean ignoreNullValue, Set<String> ignores) {
try {
Map<String, Object> settablePropertiesMap = Maps.newHashMap();
PropertyDescriptor[] propertyDescriptors = getPropertyDescriptors(from.getClass());
for (PropertyDescriptor property : propertyDescriptors) {
if (property.getReadMethod() == null || property.getWriteMethod() == null) {
continue;
}
Object value = property.getReadMethod().invoke(from);
if ((value != null || !ignoreNullValue) && !ignores.contains(property.getName())) {
settablePropertiesMap.put(property.getName(), value);
}
}
for (Map.Entry<String, Object> settableProperty : settablePropertiesMap.entrySet()) {
// Set new values
String propertyName = settableProperty.getKey();
Object propertyValue = settableProperty.getValue();
setPropertyValue(to, propertyName, propertyValue);
}
} catch (IllegalAccessException | InvocationTargetException | BeansException e) {
throw new InvalidArgumentException("Cannot merge object", e);
}
}
Aggregations