public String register()

in server/src/main/java/com/epam/indigoeln/core/service/registration/RegistrationService.java [161:215]


    public String register(String id, List<String> fullBatchNumbers) throws RegistrationException {
        Map<BatchSummary, Component> batches = getBatches(
                () -> componentRepository.findBatchSummariesByFullBatchNumbers(fullBatchNumbers),
                b -> fullBatchNumbers.contains(b.getFullNbkBatch()));

        if (fullBatchNumbers.size() != batches.size()) {
            Set<String> foundFullNbkBatches = batches.keySet()
                    .stream()
                    .map(BatchSummary::getFullNbkBatch)
                    .collect(Collectors.toSet());

            throw new RegistrationException("Unable to find batches for registration: "
                    + CollectionUtils.subtract(fullBatchNumbers, foundFullNbkBatches));
        }

        Optional<BatchSummary> inProgressOpt = batches.keySet()
                .stream()
                .filter(b -> RegistrationStatus.Status.IN_PROGRESS.toString().equals(b.getRegistrationStatus()))
                .findFirst();

        if (inProgressOpt.isPresent()) {
            throw new RegistrationException("Batch " + inProgressOpt.get().getFullNbkBatch()
                    + " is already on registration.");
        }

        List<Compound> compounds = batches.keySet()
                .stream()
                .map(b -> convert(b.getDelegate()))
                .collect(Collectors.toList());

        String jobId = getRegistrationRepository(id).register(compounds);

        batches.keySet()
                .forEach(b -> {
                    b.setRegistrationStatus(RegistrationStatus.Status.IN_PROGRESS.toString());
                    b.setRegistrationJobId(jobId);
                    b.setRegistrationRepositoryId(id);
                });

        componentRepository.saveAll(new HashSet<>(batches.values()));

        RegistrationJob registrationJob = new RegistrationJob();

        registrationJob.setRegistrationStatus(RegistrationStatus.Status.IN_PROGRESS);
        registrationJob.setRegistrationJobId(jobId);
        registrationJob.setRegistrationRepositoryId(id);
        registrationJob.setHandledBy(WebSocketUtil.getHostName());

        registrationJobRepository.save(registrationJob);

        template.convertAndSend("/topic/registration_status", fullBatchNumbers.stream()
                .collect(Collectors.toMap(fbn -> fbn, fbn -> RegistrationStatus.inProgress())));

        return jobId;
    }