RepositoryRouteResource resource = routeRequest.getData();
if ((!RepositoryRouteResource.BLOCKING_RULE_TYPE.equals(resource.getRuleType()) && (resource
.getRepositories() == null || resource.getRepositories().size() == 0))
|| resource.getId() == null || !resource.getId().equals(getRouteId(request))) {
throw new PlexusResourceException(
Status.CLIENT_ERROR_BAD_REQUEST,
"The route cannot have zero repository members!",
getNexusErrorResponse("repositories",
"The route cannot have zero repository members!"));
}
else if (RepositoryRouteResource.BLOCKING_RULE_TYPE.equals(resource.getRuleType())) {
resource.setRepositories(null);
}
try {
RepositoryPathMapping route = getRepositoryMapper().getMappings().get(getRouteId(request));
if (route == null) {
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "Route not found!");
}
ArrayList<String> mappedReposes = new ArrayList<String>(resource.getRepositories().size());
for (RepositoryRouteMemberRepository member : resource.getRepositories()) {
mappedReposes.add(member.getId());
}
RepositoryPathMapping newRoute =
new RepositoryPathMapping(route.getId(), resource2configType(resource.getRuleType()),
resource.getGroupId(), Arrays.asList(new String[]{
resource
.getPattern()
}), mappedReposes);
getRepositoryMapper().addMapping(newRoute);
getNexusConfiguration().saveConfiguration();
response.setStatus(Status.SUCCESS_NO_CONTENT);
}
catch (ConfigurationException e) {
if (e.getCause() != null && e.getCause() instanceof PatternSyntaxException) {
throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Configuration error.",
getNexusErrorResponse("pattern", e.getMessage()));
}
else {
handleConfigurationException(e);
}
}
catch (PatternSyntaxException e) {
// TODO: fix because this happens before we validate, we need to fix the validation.
ErrorResponse errorResponse = getNexusErrorResponse("*", e.getMessage());
throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Configuration error.", errorResponse);
}
/* catch ( NoSuchRepositoryAccessException e )
{
getLogger().debug( "Access Denied to a repository referenced within a route!", e );