@Test @RunWithCustomExecutor public void startDataMigration_alreadyRunning() { VitamThreadUtils.getVitamSession().setTenantId(0); DataMigrationService dataMigrationService = Mockito.mock(DataMigrationService.class); Mockito.doReturn(false).when(dataMigrationService).tryStartMongoDataUpdate(); MetadataMigrationAdminResource instance = new MetadataMigrationAdminResource(dataMigrationService); Response response = instance.startDataMigration(); assertThat(response.getStatus()).isEqualTo(Response.Status.CONFLICT.getStatusCode()); }
@Path(MIGRATION_URI) @POST @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) public Response startDataMigration() { try { VitamThreadUtils.getVitamSession().initIfAbsent(VitamConfiguration.getAdminTenant()); boolean started = this.dataMigrationService.tryStartMongoDataUpdate(); if (started) { LOGGER.info("Migration started successfully"); return Response.accepted(new ResponseMessage("OK")).build(); } else { LOGGER.warn("Migration already in progress"); return Response.status(Response.Status.CONFLICT) .entity(new ResponseMessage("Migration already in progress")).build(); } } catch (Exception e) { LOGGER.error("An error occurred during data migration", e); return Response.serverError().entity(new ResponseMessage(e.getMessage())).build(); } }
MetadataMigrationAdminResource { @Path(MIGRATION_URI) @POST @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) public Response startDataMigration() { try { VitamThreadUtils.getVitamSession().initIfAbsent(VitamConfiguration.getAdminTenant()); boolean started = this.dataMigrationService.tryStartMongoDataUpdate(); if (started) { LOGGER.info("Migration started successfully"); return Response.accepted(new ResponseMessage("OK")).build(); } else { LOGGER.warn("Migration already in progress"); return Response.status(Response.Status.CONFLICT) .entity(new ResponseMessage("Migration already in progress")).build(); } } catch (Exception e) { LOGGER.error("An error occurred during data migration", e); return Response.serverError().entity(new ResponseMessage(e.getMessage())).build(); } } }
MetadataMigrationAdminResource { @Path(MIGRATION_URI) @POST @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) public Response startDataMigration() { try { VitamThreadUtils.getVitamSession().initIfAbsent(VitamConfiguration.getAdminTenant()); boolean started = this.dataMigrationService.tryStartMongoDataUpdate(); if (started) { LOGGER.info("Migration started successfully"); return Response.accepted(new ResponseMessage("OK")).build(); } else { LOGGER.warn("Migration already in progress"); return Response.status(Response.Status.CONFLICT) .entity(new ResponseMessage("Migration already in progress")).build(); } } catch (Exception e) { LOGGER.error("An error occurred during data migration", e); return Response.serverError().entity(new ResponseMessage(e.getMessage())).build(); } } MetadataMigrationAdminResource(); @VisibleForTesting  MetadataMigrationAdminResource(
        DataMigrationService dataMigrationService); }
MetadataMigrationAdminResource { @Path(MIGRATION_URI) @POST @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) public Response startDataMigration() { try { VitamThreadUtils.getVitamSession().initIfAbsent(VitamConfiguration.getAdminTenant()); boolean started = this.dataMigrationService.tryStartMongoDataUpdate(); if (started) { LOGGER.info("Migration started successfully"); return Response.accepted(new ResponseMessage("OK")).build(); } else { LOGGER.warn("Migration already in progress"); return Response.status(Response.Status.CONFLICT) .entity(new ResponseMessage("Migration already in progress")).build(); } } catch (Exception e) { LOGGER.error("An error occurred during data migration", e); return Response.serverError().entity(new ResponseMessage(e.getMessage())).build(); } } MetadataMigrationAdminResource(); @VisibleForTesting  MetadataMigrationAdminResource(
        DataMigrationService dataMigrationService); @Path(MIGRATION_URI) @POST @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) Response startDataMigration(); @Path(MIGRATION_STATUS_URI) @GET @Produces(MediaType.APPLICATION_JSON) Response isMigrationInProgress(); }
MetadataMigrationAdminResource { @Path(MIGRATION_URI) @POST @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) public Response startDataMigration() { try { VitamThreadUtils.getVitamSession().initIfAbsent(VitamConfiguration.getAdminTenant()); boolean started = this.dataMigrationService.tryStartMongoDataUpdate(); if (started) { LOGGER.info("Migration started successfully"); return Response.accepted(new ResponseMessage("OK")).build(); } else { LOGGER.warn("Migration already in progress"); return Response.status(Response.Status.CONFLICT) .entity(new ResponseMessage("Migration already in progress")).build(); } } catch (Exception e) { LOGGER.error("An error occurred during data migration", e); return Response.serverError().entity(new ResponseMessage(e.getMessage())).build(); } } MetadataMigrationAdminResource(); @VisibleForTesting  MetadataMigrationAdminResource(
        DataMigrationService dataMigrationService); @Path(MIGRATION_URI) @POST @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) Response startDataMigration(); @Path(MIGRATION_STATUS_URI) @GET @Produces(MediaType.APPLICATION_JSON) Response isMigrationInProgress();  }