Search in sources :

Example 1 with ImportMode

use of edu.harvard.iq.dataverse.batch.jobs.importer.ImportMode 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();
    }
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Produces(javax.ws.rs.Produces) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) UpdateDatasetVersionCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetVersionCommand) DataFileTagException(edu.harvard.iq.dataverse.datasetutility.DataFileTagException) User(edu.harvard.iq.dataverse.authorization.users.User) MediaType(javax.ws.rs.core.MediaType) JsonParseException(edu.harvard.iq.dataverse.util.json.JsonParseException) MoveDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.MoveDatasetCommand) Map(java.util.Map) GetPrivateUrlCommand(edu.harvard.iq.dataverse.engine.command.impl.GetPrivateUrlCommand) DatasetField(edu.harvard.iq.dataverse.DatasetField) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) JsonObject(javax.json.JsonObject) MetadataBlockServiceBean(edu.harvard.iq.dataverse.MetadataBlockServiceBean) DataverseServiceBean(edu.harvard.iq.dataverse.DataverseServiceBean) WorkflowContext(edu.harvard.iq.dataverse.workflow.WorkflowContext) AbstractApiBean.error(edu.harvard.iq.dataverse.api.AbstractApiBean.error) DataFile(edu.harvard.iq.dataverse.DataFile) DatasetServiceBean(edu.harvard.iq.dataverse.DatasetServiceBean) EJBException(javax.ejb.EJBException) ImportMode(edu.harvard.iq.dataverse.batch.jobs.importer.ImportMode) FormDataParam(org.glassfish.jersey.media.multipart.FormDataParam) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) GetSpecificPublishedDatasetVersionCommand(edu.harvard.iq.dataverse.engine.command.impl.GetSpecificPublishedDatasetVersionCommand) CreatePrivateUrlCommand(edu.harvard.iq.dataverse.engine.command.impl.CreatePrivateUrlCommand) DataCaptureModuleUtil(edu.harvard.iq.dataverse.datacapturemodule.DataCaptureModuleUtil) JsonArrayBuilder(javax.json.JsonArrayBuilder) GET(javax.ws.rs.GET) PermissionServiceBean(edu.harvard.iq.dataverse.PermissionServiceBean) EjbDataverseEngine(edu.harvard.iq.dataverse.EjbDataverseEngine) DataverseSession(edu.harvard.iq.dataverse.DataverseSession) ResourceBundle(java.util.ResourceBundle) DatasetUtil(edu.harvard.iq.dataverse.dataset.DatasetUtil) Workflow(edu.harvard.iq.dataverse.workflow.Workflow) WorkflowServiceBean(edu.harvard.iq.dataverse.workflow.WorkflowServiceBean) Json(javax.json.Json) PublishDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.PublishDatasetCommand) EJB(javax.ejb.EJB) ExportService(edu.harvard.iq.dataverse.export.ExportService) UserNotificationServiceBean(edu.harvard.iq.dataverse.UserNotificationServiceBean) AuthenticationServiceBean(edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean) DeletePrivateUrlCommand(edu.harvard.iq.dataverse.engine.command.impl.DeletePrivateUrlCommand) UserNotification(edu.harvard.iq.dataverse.UserNotification) DeleteDatasetVersionCommand(edu.harvard.iq.dataverse.engine.command.impl.DeleteDatasetVersionCommand) StringReader(java.io.StringReader) UpdateDatasetTargetURLCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetTargetURLCommand) ListVersionsCommand(edu.harvard.iq.dataverse.engine.command.impl.ListVersionsCommand) Date(java.util.Date) DataFileServiceBean(edu.harvard.iq.dataverse.DataFileServiceBean) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) Path(javax.ws.rs.Path) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) CreateDatasetVersionCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetVersionCommand) DataCaptureModuleException(edu.harvard.iq.dataverse.datacapturemodule.DataCaptureModuleException) SettingsServiceBean(edu.harvard.iq.dataverse.settings.SettingsServiceBean) DDIExportServiceBean(edu.harvard.iq.dataverse.export.DDIExportServiceBean) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) Permission(edu.harvard.iq.dataverse.authorization.Permission) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) ScriptRequestResponse(edu.harvard.iq.dataverse.datacapturemodule.ScriptRequestResponse) GetDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.GetDatasetCommand) DestroyDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.DestroyDatasetCommand) DELETE(javax.ws.rs.DELETE) AddReplaceFileHelper(edu.harvard.iq.dataverse.datasetutility.AddReplaceFileHelper) DeleteDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.DeleteDatasetCommand) Timestamp(java.sql.Timestamp) ListRoleAssignments(edu.harvard.iq.dataverse.engine.command.impl.ListRoleAssignments) Logger(java.util.logging.Logger) MetadataBlock(edu.harvard.iq.dataverse.MetadataBlock) DatasetThumbnail(edu.harvard.iq.dataverse.dataset.DatasetThumbnail) List(java.util.List) IngestServiceBean(edu.harvard.iq.dataverse.ingest.IngestServiceBean) Response(javax.ws.rs.core.Response) JsonPrinter(edu.harvard.iq.dataverse.util.json.JsonPrinter) ImportFromFileSystemCommand(edu.harvard.iq.dataverse.engine.command.impl.ImportFromFileSystemCommand) ReturnDatasetToAuthorCommand(edu.harvard.iq.dataverse.engine.command.impl.ReturnDatasetToAuthorCommand) SubmitDatasetForReviewCommand(edu.harvard.iq.dataverse.engine.command.impl.SubmitDatasetForReviewCommand) JsonObjectBuilder(javax.json.JsonObjectBuilder) OptionalFileParams(edu.harvard.iq.dataverse.datasetutility.OptionalFileParams) GetDraftDatasetVersionCommand(edu.harvard.iq.dataverse.engine.command.impl.GetDraftDatasetVersionCommand) DatasetLock(edu.harvard.iq.dataverse.DatasetLock) PathParam(javax.ws.rs.PathParam) SystemConfig(edu.harvard.iq.dataverse.util.SystemConfig) HashMap(java.util.HashMap) GetLatestPublishedDatasetVersionCommand(edu.harvard.iq.dataverse.engine.command.impl.GetLatestPublishedDatasetVersionCommand) EjbUtil(edu.harvard.iq.dataverse.util.EjbUtil) Level(java.util.logging.Level) Inject(javax.inject.Inject) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) NoFilesException(edu.harvard.iq.dataverse.datasetutility.NoFilesException) Dataverse(edu.harvard.iq.dataverse.Dataverse) Command(edu.harvard.iq.dataverse.engine.command.Command) UpdateDatasetThumbnailCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetThumbnailCommand) POST(javax.ws.rs.POST) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) Dataset(edu.harvard.iq.dataverse.Dataset) GetLatestAccessibleDatasetVersionCommand(edu.harvard.iq.dataverse.engine.command.impl.GetLatestAccessibleDatasetVersionCommand) AssignRoleCommand(edu.harvard.iq.dataverse.engine.command.impl.AssignRoleCommand) DatasetFieldServiceBean(edu.harvard.iq.dataverse.DatasetFieldServiceBean) PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) RequestRsyncScriptCommand(edu.harvard.iq.dataverse.engine.command.impl.RequestRsyncScriptCommand) PublishDatasetResult(edu.harvard.iq.dataverse.engine.command.impl.PublishDatasetResult) SetDatasetCitationDateCommand(edu.harvard.iq.dataverse.engine.command.impl.SetDatasetCitationDateCommand) PUT(javax.ws.rs.PUT) InputStream(java.io.InputStream) ImportFromFileSystemCommand(edu.harvard.iq.dataverse.engine.command.impl.ImportFromFileSystemCommand) Dataset(edu.harvard.iq.dataverse.Dataset) JsonObject(javax.json.JsonObject) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Timestamp(java.sql.Timestamp) Date(java.util.Date) ImportMode(edu.harvard.iq.dataverse.batch.jobs.importer.ImportMode) List(java.util.List) JsonObjectBuilder(javax.json.JsonObjectBuilder) Map(java.util.Map) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 2 with ImportMode

use of edu.harvard.iq.dataverse.batch.jobs.importer.ImportMode in project dataverse by IQSS.

the class FileRecordJobResource method getFilesystemImport.

@POST
@Path("import/datasets/files/{identifier}")
@Produces(MediaType.APPLICATION_JSON)
public Response getFilesystemImport(@PathParam("identifier") String identifier, @QueryParam("mode") @DefaultValue("MERGE") String mode, /*@QueryParam("fileMode") @DefaultValue("package_file") String fileMode*/
@QueryParam("uploadFolder") String uploadFolder, @QueryParam("totalSize") Long totalSize) {
    return response(req -> {
        ImportMode importMode = ImportMode.MERGE;
        // Switch to this if you ever need to use something other than MERGE.
        // ImportMode importMode = ImportMode.valueOf(mode);
        JsonObject jsonObject = execCommand(new ImportFromFileSystemCommand(req, findDatasetOrDie(identifier), uploadFolder, totalSize, importMode));
        String returnString = jsonObject.getString("message");
        if (!returnString.equals("FileSystemImportJob in progress")) {
            return error(Response.Status.INTERNAL_SERVER_ERROR, returnString);
        }
        return ok(Json.createObjectBuilder().add("message", returnString).add("executionId", jsonObject.getInt("executionId")));
    });
}
Also used : ImportMode(edu.harvard.iq.dataverse.batch.jobs.importer.ImportMode) ImportFromFileSystemCommand(edu.harvard.iq.dataverse.engine.command.impl.ImportFromFileSystemCommand) JsonObject(javax.json.JsonObject) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

ImportMode (edu.harvard.iq.dataverse.batch.jobs.importer.ImportMode)2 ImportFromFileSystemCommand (edu.harvard.iq.dataverse.engine.command.impl.ImportFromFileSystemCommand)2 JsonObject (javax.json.JsonObject)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 DataFile (edu.harvard.iq.dataverse.DataFile)1 DataFileServiceBean (edu.harvard.iq.dataverse.DataFileServiceBean)1 Dataset (edu.harvard.iq.dataverse.Dataset)1 DatasetField (edu.harvard.iq.dataverse.DatasetField)1 DatasetFieldServiceBean (edu.harvard.iq.dataverse.DatasetFieldServiceBean)1 DatasetFieldType (edu.harvard.iq.dataverse.DatasetFieldType)1 DatasetLock (edu.harvard.iq.dataverse.DatasetLock)1 DatasetServiceBean (edu.harvard.iq.dataverse.DatasetServiceBean)1 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)1 Dataverse (edu.harvard.iq.dataverse.Dataverse)1 DataverseServiceBean (edu.harvard.iq.dataverse.DataverseServiceBean)1 DataverseSession (edu.harvard.iq.dataverse.DataverseSession)1 EjbDataverseEngine (edu.harvard.iq.dataverse.EjbDataverseEngine)1 MetadataBlock (edu.harvard.iq.dataverse.MetadataBlock)1