Created
September 27, 2024 14:17
-
-
Save shvyrev/a20871e2d20f2fa806773ded95d7a1a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.bft.bftresend.business.zags.processors; | |
import lombok.RequiredArgsConstructor; | |
import lombok.extern.slf4j.Slf4j; | |
import org.apache.camel.Exchange; | |
import org.apache.camel.Processor; | |
import org.bft.bftresend.business.zags.model.ZagsProxy; | |
import org.bft.bftresend.services.ElectronicArchiveResource; | |
import org.bft.bftresend.services.MessageFormater; | |
import org.bft.bftresend.utils.MessageProcessor; | |
import org.springframework.stereotype.Component; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.UUID; | |
import java.util.function.Predicate; | |
import static java.nio.charset.StandardCharsets.UTF_8; | |
import static org.bft.bftresend.utils.Const.FILE_UUID_PREFIX; | |
/** | |
* Читает содержимое из файла лога. Находит идентификаторы файлов соответсвующее идентификатором сообщений. | |
*/ | |
@Slf4j | |
@Component | |
@RequiredArgsConstructor | |
public class ZagsReadFileByFileUUIDProcessor implements Processor, MessageProcessor { | |
private final MessageFormater messageFormater; | |
private final ElectronicArchiveResource eaResource; | |
@Override | |
public void process(Exchange exchange) throws Exception { | |
var fileUUIDs = (List<UUID>)exchange.getProperty("files", List.class); | |
List<ZagsProxy> proxyList = (List<ZagsProxy>)exchange.getProperty("proxies", List.class); | |
Long jobId = exchange.getProperty("jobId", Long.class); | |
var filePath = exchange.getIn().getBody().toString(); | |
Predicate<String> predicate = line -> proxyList.contains(getProxy(line)) && line.contains(FILE_UUID_PREFIX); | |
List<String> result = new ArrayList<>(); | |
try (var lines = Files.lines(Paths.get(filePath), UTF_8).filter(predicate)) { | |
lines.map(line -> getMessageLogInfo(jobId, line)) | |
.filter(info -> fileUUIDs.contains(info.fileId())) | |
.forEach(messageLogInfo -> { | |
eaResource.loadFile(messageLogInfo.fileId(), fileModel -> { | |
String text = messageFormater.formatZagsForRabbit( | |
fileModel.getFileName(), messageLogInfo.messageId()); | |
result.add(text); | |
}); | |
}); | |
exchange.getIn().setBody(result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment