@Test @RunWithCustomExecutor public void should_throw_exception_when_offer_synchronization_request_with_missing_strategy() { OfferSyncRequest offerSyncRequest = createOfferSyncRequest() .setStrategyId(null); AdminOfferSyncResource instance = new AdminOfferSyncResource(offerSyncService); assertThatThrownBy(() -> instance.startSynchronization(offerSyncRequest)) .isInstanceOf(IllegalArgumentException.class); verifyNoMoreInteractions(offerSyncService); }
@Path(OFFER_SYNC_URI) @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) public Response startSynchronization(OfferSyncRequest offerSyncRequest) { ParametersChecker.checkParameter("source offer is mandatory.", offerSyncRequest.getSourceOffer()); ParametersChecker.checkParameter("target offer is mandatory.", offerSyncRequest.getTargetOffer()); if (offerSyncRequest.getSourceOffer().equals(offerSyncRequest.getTargetOffer())) { throw new IllegalArgumentException("Source offer cannot be the same as target offer"); } ParametersChecker.checkParameter("strategyId is mandatory.", offerSyncRequest.getStrategyId()); ParametersChecker.checkParameter("tenantId is mandatory.", offerSyncRequest.getTenantId()); ParametersChecker.checkParameter("container is mandatory.", offerSyncRequest.getContainer()); if (!VitamConfiguration.getTenants().contains(offerSyncRequest.getTenantId())) { throw new IllegalArgumentException("Invalid tenant " + offerSyncRequest.getTenantId()); } VitamThreadUtils.getVitamSession().setTenantId(offerSyncRequest.getTenantId()); VitamThreadUtils.getVitamSession() .setRequestId(GUIDFactory.newRequestIdGUID(offerSyncRequest.getTenantId())); DataCategory dataCategory = DataCategory.getByCollectionName(offerSyncRequest.getContainer()); LOGGER.info(String.format("Starting %s offer synchronization from the %s source offer with %d%n offset.", offerSyncRequest.getTargetOffer(), offerSyncRequest.getSourceOffer(), offerSyncRequest.getOffset())); boolean started = offerSyncService .startSynchronization(offerSyncRequest.getSourceOffer(), offerSyncRequest.getTargetOffer(), offerSyncRequest.getStrategyId(), dataCategory, offerSyncRequest.getOffset()); Response.Status status; if (started) { LOGGER.info("Offer synchronization started"); status = Response.Status.OK; } else { LOGGER.warn("Another synchronization process is already running"); status = Response.Status.CONFLICT; } return Response.status(status) .header(X_REQUEST_ID, VitamThreadUtils.getVitamSession().getRequestId()) .build(); }
AdminOfferSyncResource { @Path(OFFER_SYNC_URI) @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) public Response startSynchronization(OfferSyncRequest offerSyncRequest) { ParametersChecker.checkParameter("source offer is mandatory.", offerSyncRequest.getSourceOffer()); ParametersChecker.checkParameter("target offer is mandatory.", offerSyncRequest.getTargetOffer()); if (offerSyncRequest.getSourceOffer().equals(offerSyncRequest.getTargetOffer())) { throw new IllegalArgumentException("Source offer cannot be the same as target offer"); } ParametersChecker.checkParameter("strategyId is mandatory.", offerSyncRequest.getStrategyId()); ParametersChecker.checkParameter("tenantId is mandatory.", offerSyncRequest.getTenantId()); ParametersChecker.checkParameter("container is mandatory.", offerSyncRequest.getContainer()); if (!VitamConfiguration.getTenants().contains(offerSyncRequest.getTenantId())) { throw new IllegalArgumentException("Invalid tenant " + offerSyncRequest.getTenantId()); } VitamThreadUtils.getVitamSession().setTenantId(offerSyncRequest.getTenantId()); VitamThreadUtils.getVitamSession() .setRequestId(GUIDFactory.newRequestIdGUID(offerSyncRequest.getTenantId())); DataCategory dataCategory = DataCategory.getByCollectionName(offerSyncRequest.getContainer()); LOGGER.info(String.format("Starting %s offer synchronization from the %s source offer with %d%n offset.", offerSyncRequest.getTargetOffer(), offerSyncRequest.getSourceOffer(), offerSyncRequest.getOffset())); boolean started = offerSyncService .startSynchronization(offerSyncRequest.getSourceOffer(), offerSyncRequest.getTargetOffer(), offerSyncRequest.getStrategyId(), dataCategory, offerSyncRequest.getOffset()); Response.Status status; if (started) { LOGGER.info("Offer synchronization started"); status = Response.Status.OK; } else { LOGGER.warn("Another synchronization process is already running"); status = Response.Status.CONFLICT; } return Response.status(status) .header(X_REQUEST_ID, VitamThreadUtils.getVitamSession().getRequestId()) .build(); } }
AdminOfferSyncResource { @Path(OFFER_SYNC_URI) @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) public Response startSynchronization(OfferSyncRequest offerSyncRequest) { ParametersChecker.checkParameter("source offer is mandatory.", offerSyncRequest.getSourceOffer()); ParametersChecker.checkParameter("target offer is mandatory.", offerSyncRequest.getTargetOffer()); if (offerSyncRequest.getSourceOffer().equals(offerSyncRequest.getTargetOffer())) { throw new IllegalArgumentException("Source offer cannot be the same as target offer"); } ParametersChecker.checkParameter("strategyId is mandatory.", offerSyncRequest.getStrategyId()); ParametersChecker.checkParameter("tenantId is mandatory.", offerSyncRequest.getTenantId()); ParametersChecker.checkParameter("container is mandatory.", offerSyncRequest.getContainer()); if (!VitamConfiguration.getTenants().contains(offerSyncRequest.getTenantId())) { throw new IllegalArgumentException("Invalid tenant " + offerSyncRequest.getTenantId()); } VitamThreadUtils.getVitamSession().setTenantId(offerSyncRequest.getTenantId()); VitamThreadUtils.getVitamSession() .setRequestId(GUIDFactory.newRequestIdGUID(offerSyncRequest.getTenantId())); DataCategory dataCategory = DataCategory.getByCollectionName(offerSyncRequest.getContainer()); LOGGER.info(String.format("Starting %s offer synchronization from the %s source offer with %d%n offset.", offerSyncRequest.getTargetOffer(), offerSyncRequest.getSourceOffer(), offerSyncRequest.getOffset())); boolean started = offerSyncService .startSynchronization(offerSyncRequest.getSourceOffer(), offerSyncRequest.getTargetOffer(), offerSyncRequest.getStrategyId(), dataCategory, offerSyncRequest.getOffset()); Response.Status status; if (started) { LOGGER.info("Offer synchronization started"); status = Response.Status.OK; } else { LOGGER.warn("Another synchronization process is already running"); status = Response.Status.CONFLICT; } return Response.status(status) .header(X_REQUEST_ID, VitamThreadUtils.getVitamSession().getRequestId()) .build(); } AdminOfferSyncResource(StorageDistribution distribution, StorageConfiguration storageConfiguration); @VisibleForTesting  AdminOfferSyncResource(
        OfferSyncService offerSyncService); }
AdminOfferSyncResource { @Path(OFFER_SYNC_URI) @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) public Response startSynchronization(OfferSyncRequest offerSyncRequest) { ParametersChecker.checkParameter("source offer is mandatory.", offerSyncRequest.getSourceOffer()); ParametersChecker.checkParameter("target offer is mandatory.", offerSyncRequest.getTargetOffer()); if (offerSyncRequest.getSourceOffer().equals(offerSyncRequest.getTargetOffer())) { throw new IllegalArgumentException("Source offer cannot be the same as target offer"); } ParametersChecker.checkParameter("strategyId is mandatory.", offerSyncRequest.getStrategyId()); ParametersChecker.checkParameter("tenantId is mandatory.", offerSyncRequest.getTenantId()); ParametersChecker.checkParameter("container is mandatory.", offerSyncRequest.getContainer()); if (!VitamConfiguration.getTenants().contains(offerSyncRequest.getTenantId())) { throw new IllegalArgumentException("Invalid tenant " + offerSyncRequest.getTenantId()); } VitamThreadUtils.getVitamSession().setTenantId(offerSyncRequest.getTenantId()); VitamThreadUtils.getVitamSession() .setRequestId(GUIDFactory.newRequestIdGUID(offerSyncRequest.getTenantId())); DataCategory dataCategory = DataCategory.getByCollectionName(offerSyncRequest.getContainer()); LOGGER.info(String.format("Starting %s offer synchronization from the %s source offer with %d%n offset.", offerSyncRequest.getTargetOffer(), offerSyncRequest.getSourceOffer(), offerSyncRequest.getOffset())); boolean started = offerSyncService .startSynchronization(offerSyncRequest.getSourceOffer(), offerSyncRequest.getTargetOffer(), offerSyncRequest.getStrategyId(), dataCategory, offerSyncRequest.getOffset()); Response.Status status; if (started) { LOGGER.info("Offer synchronization started"); status = Response.Status.OK; } else { LOGGER.warn("Another synchronization process is already running"); status = Response.Status.CONFLICT; } return Response.status(status) .header(X_REQUEST_ID, VitamThreadUtils.getVitamSession().getRequestId()) .build(); } AdminOfferSyncResource(StorageDistribution distribution, StorageConfiguration storageConfiguration); @VisibleForTesting  AdminOfferSyncResource(
        OfferSyncService offerSyncService); @Path(OFFER_PARTIAL_SYNC_URI) @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) Response startPartialSynchronization(OfferPartialSyncRequest offerPartialSyncRequest); @Path(OFFER_SYNC_URI) @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) Response startSynchronization(OfferSyncRequest offerSyncRequest); @Path(OFFER_SYNC_URI) @HEAD @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) Response isOfferSynchronizationRunning(); @Path(OFFER_SYNC_URI) @GET @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) Response getLastOfferSynchronizationStatus(); }
AdminOfferSyncResource { @Path(OFFER_SYNC_URI) @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) public Response startSynchronization(OfferSyncRequest offerSyncRequest) { ParametersChecker.checkParameter("source offer is mandatory.", offerSyncRequest.getSourceOffer()); ParametersChecker.checkParameter("target offer is mandatory.", offerSyncRequest.getTargetOffer()); if (offerSyncRequest.getSourceOffer().equals(offerSyncRequest.getTargetOffer())) { throw new IllegalArgumentException("Source offer cannot be the same as target offer"); } ParametersChecker.checkParameter("strategyId is mandatory.", offerSyncRequest.getStrategyId()); ParametersChecker.checkParameter("tenantId is mandatory.", offerSyncRequest.getTenantId()); ParametersChecker.checkParameter("container is mandatory.", offerSyncRequest.getContainer()); if (!VitamConfiguration.getTenants().contains(offerSyncRequest.getTenantId())) { throw new IllegalArgumentException("Invalid tenant " + offerSyncRequest.getTenantId()); } VitamThreadUtils.getVitamSession().setTenantId(offerSyncRequest.getTenantId()); VitamThreadUtils.getVitamSession() .setRequestId(GUIDFactory.newRequestIdGUID(offerSyncRequest.getTenantId())); DataCategory dataCategory = DataCategory.getByCollectionName(offerSyncRequest.getContainer()); LOGGER.info(String.format("Starting %s offer synchronization from the %s source offer with %d%n offset.", offerSyncRequest.getTargetOffer(), offerSyncRequest.getSourceOffer(), offerSyncRequest.getOffset())); boolean started = offerSyncService .startSynchronization(offerSyncRequest.getSourceOffer(), offerSyncRequest.getTargetOffer(), offerSyncRequest.getStrategyId(), dataCategory, offerSyncRequest.getOffset()); Response.Status status; if (started) { LOGGER.info("Offer synchronization started"); status = Response.Status.OK; } else { LOGGER.warn("Another synchronization process is already running"); status = Response.Status.CONFLICT; } return Response.status(status) .header(X_REQUEST_ID, VitamThreadUtils.getVitamSession().getRequestId()) .build(); } AdminOfferSyncResource(StorageDistribution distribution, StorageConfiguration storageConfiguration); @VisibleForTesting  AdminOfferSyncResource(
        OfferSyncService offerSyncService); @Path(OFFER_PARTIAL_SYNC_URI) @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) Response startPartialSynchronization(OfferPartialSyncRequest offerPartialSyncRequest); @Path(OFFER_SYNC_URI) @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) Response startSynchronization(OfferSyncRequest offerSyncRequest); @Path(OFFER_SYNC_URI) @HEAD @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) Response isOfferSynchronizationRunning(); @Path(OFFER_SYNC_URI) @GET @Produces(MediaType.APPLICATION_JSON) @VitamAuthentication(authentLevel = AuthenticationLevel.BASIC_AUTHENT) Response getLastOfferSynchronizationStatus();  }