use of javax.ws.rs.PathParam in project dataverse by IQSS.
the class Datasets method receiveChecksumValidationResults.
@POST
@Path("{identifier}/dataCaptureModule/checksumValidation")
public Response receiveChecksumValidationResults(@PathParam("identifier") String id, JsonObject jsonFromDcm) {
logger.log(Level.FINE, "jsonFromDcm: {0}", jsonFromDcm);
AuthenticatedUser authenticatedUser = null;
try {
authenticatedUser = findAuthenticatedUserOrDie();
} catch (WrappedResponse ex) {
return error(Response.Status.BAD_REQUEST, "Authentication is required.");
}
if (!authenticatedUser.isSuperuser()) {
return error(Response.Status.FORBIDDEN, "Superusers only.");
}
String statusMessageFromDcm = jsonFromDcm.getString("status");
try {
Dataset dataset = findDatasetOrDie(id);
if ("validation passed".equals(statusMessageFromDcm)) {
String uploadFolder = jsonFromDcm.getString("uploadFolder");
int totalSize = jsonFromDcm.getInt("totalSize");
ImportMode importMode = ImportMode.MERGE;
try {
JsonObject jsonFromImportJobKickoff = execCommand(new ImportFromFileSystemCommand(createDataverseRequest(findUserOrDie()), dataset, uploadFolder, new Long(totalSize), importMode));
long jobId = jsonFromImportJobKickoff.getInt("executionId");
String message = jsonFromImportJobKickoff.getString("message");
JsonObjectBuilder job = Json.createObjectBuilder();
job.add("jobId", jobId);
job.add("message", message);
return ok(job);
} catch (WrappedResponse wr) {
String message = wr.getMessage();
return error(Response.Status.INTERNAL_SERVER_ERROR, "Uploaded files have passed checksum validation but something went wrong while attempting to put the files into Dataverse. Message was '" + message + "'.");
}
} else if ("validation failed".equals(statusMessageFromDcm)) {
Map<String, AuthenticatedUser> distinctAuthors = permissionService.getDistinctUsersWithPermissionOn(Permission.EditDataset, dataset);
distinctAuthors.values().forEach((value) -> {
userNotificationService.sendNotification((AuthenticatedUser) value, new Timestamp(new Date().getTime()), UserNotification.Type.CHECKSUMFAIL, dataset.getId());
});
List<AuthenticatedUser> superUsers = authenticationServiceBean.findSuperUsers();
if (superUsers != null && !superUsers.isEmpty()) {
superUsers.forEach((au) -> {
userNotificationService.sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.CHECKSUMFAIL, dataset.getId());
});
}
return ok("User notified about checksum validation failure.");
} else {
return error(Response.Status.BAD_REQUEST, "Unexpected status cannot be processed: " + statusMessageFromDcm);
}
} catch (WrappedResponse ex) {
return ex.getResponse();
}
}
use of javax.ws.rs.PathParam in project plugin-prov by ligoj.
the class ImportCatalogResourceTest method updateCatalog.
@Test
public void updateCatalog() throws Exception {
final ImportCatalogResource resource = new ImportCatalogResource() {
@Override
public ImportCatalogStatus getTask(@PathParam("node") final String node) {
return getTaskRepository().findBy("locked.id", node);
}
};
applicationContext.getAutowireCapableBeanFactory().autowireBean(resource);
// Replace the locator for the custom provider
resource.locator = Mockito.mock(ServicePluginLocator.class);
final ImportCatalogService service = Mockito.mock(ImportCatalogService.class);
Mockito.when(resource.locator.getResource("service:prov:test", ImportCatalogService.class)).thenReturn(service);
final ImportCatalogStatus status = resource.updateCatalog("service:prov:test:account");
Assertions.assertEquals(DEFAULT_USER, status.getAuthor());
Assertions.assertNull(status.getEnd());
Assertions.assertNull(status.getLocation());
Assertions.assertEquals("service:prov:test", status.getLocked().getId());
Assertions.assertNotNull(status.getStart());
Assertions.assertNull(status.getLocation());
Assertions.assertEquals(0, status.getDone());
Assertions.assertEquals(0, status.getWorkload());
Assertions.assertFalse(resource.getTask("service:prov:test").isFinished());
Thread.sleep(100);
Mockito.verify(service).updateCatalog("service:prov:test");
}
use of javax.ws.rs.PathParam in project plugin-prov by ligoj.
the class ProvUsageResource method delete.
/**
* Delete an usage. When the usage is associated to a quote or a resource, it is replaced by a <code>null</code>
* reference.
*
* @param subscription
* The subscription identifier, will be used to filter the usages from the associated provider.
* @param name
* The {@link ProvUsage} name.
* @return The updated cost. Only relevant when at least one resource was associated to this usage.
*/
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Path("{subscription:\\d+}/usage/{name}")
public UpdatedCost delete(@PathParam("subscription") final int subscription, @PathParam("name") final String name) {
final ProvUsage entity = resource.findConfiguredByName(repository, name, subscription);
final ProvQuote quote = entity.getConfiguration();
final UpdatedCost cost = new UpdatedCost();
// Prepare the updated cost of updated instances
final Map<Integer, FloatingCost> costs = cost.getRelatedCosts();
cost.setRelatedCosts(costs);
// Update the cost of all related instances
if (entity.equals(quote.getUsage())) {
// Update cost of all instances without explicit usage
quote.setUsage(null);
quote.getInstances().stream().filter(i -> i.getUsage() == null).forEach(i -> costs.put(i.getId(), instanceResource.addCost(i, instanceResource::refresh)));
}
quote.getInstances().stream().filter(i -> entity.equals(i.getUsage())).peek(i -> i.setUsage(null)).forEach(i -> costs.put(i.getId(), instanceResource.addCost(i, instanceResource::refresh)));
// All references are deleted, delete the usage entity
repository.delete(entity);
// Save and update the costs
cost.setTotalCost(resource.toFloatingCost(entity.getConfiguration()));
return cost;
}
use of javax.ws.rs.PathParam in project vespa by vespa-engine.
the class InstanceResource method getSlobrokEntries.
@GET
@Path("/{instanceId}/slobrok")
@Produces(MediaType.APPLICATION_JSON)
public List<SlobrokEntryResponse> getSlobrokEntries(@PathParam("instanceId") String instanceId, @QueryParam("pattern") String pattern) {
ApplicationInstanceReference reference = parseInstanceId(instanceId);
ApplicationId applicationId = OrchestratorUtil.toApplicationId(reference);
if (pattern == null) {
pattern = DEFAULT_SLOBROK_PATTERN;
}
List<Mirror.Entry> entries = slobrokApi.lookup(applicationId, pattern);
return entries.stream().map(entry -> new SlobrokEntryResponse(entry.getName(), entry.getSpec())).collect(Collectors.toList());
}
use of javax.ws.rs.PathParam in project streamline by hortonworks.
the class NamespaceCatalogResource method setServicesToClusterInNamespace.
@POST
@Path("/namespaces/{id}/mapping/bulk")
@Timed
public Response setServicesToClusterInNamespace(@PathParam("id") Long namespaceId, List<NamespaceServiceClusterMap> mappings, @Context SecurityContext securityContext) {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_SUPER_ADMIN, Namespace.NAMESPACE, namespaceId, WRITE);
Namespace namespace = environmentService.getNamespace(namespaceId);
if (namespace == null) {
throw EntityNotFoundException.byId(namespaceId.toString());
}
String streamingEngine = namespace.getStreamingEngine();
String timeSeriesDB = namespace.getTimeSeriesDB();
Collection<NamespaceServiceClusterMap> existing = environmentService.listServiceClusterMapping(namespaceId);
Optional<NamespaceServiceClusterMap> existingStreamingEngine = existing.stream().filter(m -> m.getServiceName().equals(streamingEngine)).findFirst();
// indicates that mapping of streaming engine has been changed or removed
if (existingStreamingEngine.isPresent() && !mappings.contains(existingStreamingEngine.get())) {
assertNoTopologyReferringNamespaceIsRunning(namespaceId, WSUtils.getUserFromSecurityContext(securityContext));
}
// we're OK to just check with new mappings since we will remove existing mappings
assertServiceIsUnique(mappings, streamingEngine);
assertServiceIsUnique(mappings, timeSeriesDB);
// remove any existing mapping for (namespace, service name) pairs
Collection<NamespaceServiceClusterMap> existingMappings = environmentService.listServiceClusterMapping(namespaceId);
if (existingMappings != null) {
existingMappings.forEach(m -> environmentService.removeServiceClusterMapping(m.getNamespaceId(), m.getServiceName(), m.getClusterId()));
}
List<NamespaceServiceClusterMap> newMappings = mappings.stream().map(environmentService::addOrUpdateServiceClusterMapping).collect(toList());
return WSUtils.respondEntities(newMappings, CREATED);
}
Aggregations