Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dms integration return content coos #1760

Merged
merged 8 commits into from
Jun 13, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
<camunda:in sourceExpression="${date}" target="date" />
<camunda:in sourceExpression="${user}" target="user" />
<camunda:in sourceExpression="test/" target="filepaths" />
<camunda:out source="documentCoo" target="documentCoo" />
<camunda:out source="contentCoos" target="contentCoos" />
<camunda:inputOutput>
<camunda:inputParameter name="date">${execution.getVariable("date")}</camunda:inputParameter>
</camunda:inputOutput>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ execution.setVariable('firstCoo', tFirstCoo);</bpmn:script>
<camunda:in sourceExpression="${documentCoo}" target="documentCoo" />
<camunda:in sourceExpression="${user}" target="user" />
<camunda:in sourceExpression="updatedocs/" target="filepaths" />
<camunda:out source="contentCoos" target="contentCoos" />
</bpmn:extensionElements>
<bpmn:incoming>Flow_1t2z215</bpmn:incoming>
<bpmn:outgoing>Flow_17v6het</bpmn:outgoing>
Expand Down Expand Up @@ -321,6 +322,7 @@ execution.setVariable('firstCoo', tFirstCoo);</bpmn:script>
<camunda:in sourceExpression="docs/" target="filepaths" />
<camunda:in sourceExpression="${date}" target="date" />
<camunda:out source="documentCoo" target="documentCoo" />
<camunda:out source="contentCoos" target="contentCoos" />
<camunda:inputOutput>
<camunda:inputParameter name="date">${execution.getVariable("date")}</camunda:inputParameter>
</camunda:inputOutput>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<camunda:in sourceExpression="${documentCoo}" target="documentCoo" />
<camunda:in sourceExpression="${user}" target="user" />
<camunda:in sourceExpression="test/" target="filepaths" />
<camunda:out source="contentCoos" target="contentCoos" />
</bpmn:extensionElements>
<bpmn:incoming>Flow_16a04uf</bpmn:incoming>
<bpmn:outgoing>Flow_1fnfcyp</bpmn:outgoing>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.muenchen.oss.digiwf.dms.integration.adapter.in;

import de.muenchen.oss.digiwf.dms.integration.application.port.in.*;
import de.muenchen.oss.digiwf.dms.integration.domain.DocumentResponse;
import de.muenchen.oss.digiwf.dms.integration.domain.DocumentType;
import de.muenchen.oss.digiwf.dms.integration.domain.Procedure;
import de.muenchen.oss.digiwf.message.process.api.ErrorApi;
Expand Down Expand Up @@ -90,7 +91,7 @@ public Consumer<Message<CreateDocumentDto>> createDocument() {
return message -> {
withErrorHandling(message, () -> {
final CreateDocumentDto createDocumentDto = message.getPayload();
final String document = this.createDocumentInPort.createDocument(
DocumentResponse documentResponse = this.createDocumentInPort.createDocument(
createDocumentDto.getProcedureCoo(),
createDocumentDto.getTitle(),
createDocumentDto.getDate(),
Expand All @@ -103,7 +104,10 @@ public Consumer<Message<CreateDocumentDto>> createDocument() {

this.correlateMessage(message.getHeaders().get(DIGIWF_PROCESS_INSTANCE_ID).toString(),
message.getHeaders().get(TYPE).toString(),
message.getHeaders().get(DIGIWF_INTEGRATION_NAME).toString(), Map.of("documentCoo", document));
message.getHeaders().get(DIGIWF_INTEGRATION_NAME).toString(), Map.of(
"documentCoo", documentResponse.getDocumentCoo(),
"contentCoos", documentResponse.getContentCoos()
));
});
};
}
Expand All @@ -112,7 +116,7 @@ public Consumer<Message<UpdateDocumentDto>> updateDocument() {
return message -> {
withErrorHandling(message, () -> {
final UpdateDocumentDto updateDocumentDto = message.getPayload();
this.updateDocumentInPort.updateDocument(
DocumentResponse documentResponse = this.updateDocumentInPort.updateDocument(
updateDocumentDto.getDocumentCoo(),
updateDocumentDto.getUser(),
DocumentType.valueOf(updateDocumentDto.getType()),
Expand All @@ -123,7 +127,9 @@ public Consumer<Message<UpdateDocumentDto>> updateDocument() {

this.correlateMessage(message.getHeaders().get(DIGIWF_PROCESS_INSTANCE_ID).toString(),
message.getHeaders().get(TYPE).toString(),
message.getHeaders().get(DIGIWF_INTEGRATION_NAME).toString(), Map.of());
message.getHeaders().get(DIGIWF_INTEGRATION_NAME).toString(), Map.of(
"contentCoos", documentResponse.getContentCoos()
));
});
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.lang.NonNull;

import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
Expand All @@ -23,6 +25,7 @@ public class FabasoftAdapter implements
UpdateDocumentOutPort,
DepositObjectOutPort,
CancelObjectOutPort,
ListContentOutPort,
ReadContentOutPort,
SearchFileOutPort,
SearchSubjectAreaOutPort,
Expand Down Expand Up @@ -319,6 +322,21 @@ public void cancelObject(final String objectCoo, final String user) {
dmsErrorHandler.handleError(response.getStatus(), response.getErrormessage());
}

@Override
public List<String> listContentCoos(@NotNull String documentCoo, @NonNull final String user) {
ReadDocumentGIObjects request = new ReadDocumentGIObjects();
request.setUserlogin(user);
request.setBusinessapp(this.properties.getBusinessapp());
request.setObjaddress(documentCoo);

ReadDocumentGIObjectsResponse response = this.wsClient.readDocumentGIObjects(request);
dmsErrorHandler.handleError(response.getStatus(), response.getErrormessage());

return response.getGiobjecttype().getLHMBAI151700GIObjectType().stream()
.map(LHMBAI151700GIObjectType::getLHMBAI151700Objaddress)
.toList();
}

@Override
public List<Content> readContent(final List<String> coos, final String user) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package de.muenchen.oss.digiwf.dms.integration.application.port.in;

import de.muenchen.oss.digiwf.dms.integration.domain.DocumentResponse;
import de.muenchen.oss.digiwf.dms.integration.domain.DocumentType;

import java.time.LocalDate;
import java.util.List;

public interface CreateDocumentInPort {

String createDocument(final String procedureCOO, final String title, final LocalDate date, final String user, DocumentType type,
final List<String> filepaths, final String fileContext, final String processDefinition);
DocumentResponse createDocument(final String procedureCOO, final String title, final LocalDate date, final String user, DocumentType type,
final List<String> filepaths, final String fileContext, final String processDefinition);

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package de.muenchen.oss.digiwf.dms.integration.application.port.in;

import de.muenchen.oss.digiwf.dms.integration.domain.DocumentResponse;
import de.muenchen.oss.digiwf.dms.integration.domain.DocumentType;

import java.util.List;

public interface UpdateDocumentInPort {

void updateDocument(String documentCOO, String user, DocumentType type, List<String> filepaths, String fileContext, String processDefinition);
DocumentResponse updateDocument(String documentCOO, String user, DocumentType type, List<String> filepaths, String fileContext, String processDefinition);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package de.muenchen.oss.digiwf.dms.integration.application.port.out;

import org.springframework.lang.NonNull;

import java.util.List;

public interface ListContentOutPort {
/**
* List all content coos for a document coo.
*
* @param documentCoo The document coo to list the content for.
* @return The list of content coos contained in the document.
*/
List<String> listContentCoos(@NonNull final String documentCoo, @NonNull final String user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import de.muenchen.oss.digiwf.dms.integration.application.port.in.CreateDocumentInPort;
import de.muenchen.oss.digiwf.dms.integration.application.port.out.CreateDocumentOutPort;
import de.muenchen.oss.digiwf.dms.integration.application.port.out.ListContentOutPort;
import de.muenchen.oss.digiwf.dms.integration.application.port.out.LoadFileOutPort;
import de.muenchen.oss.digiwf.dms.integration.domain.Content;
import de.muenchen.oss.digiwf.dms.integration.domain.Document;
import de.muenchen.oss.digiwf.dms.integration.domain.DocumentResponse;
import de.muenchen.oss.digiwf.dms.integration.domain.DocumentType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
Expand All @@ -19,9 +21,10 @@ public class CreateDocumentUseCase implements CreateDocumentInPort {
private final CreateDocumentOutPort createDocumentOutPort;

private final LoadFileOutPort loadFileOutPort;
private final ListContentOutPort listContentOutPort;

@Override
public String createDocument(
public DocumentResponse createDocument(
final String procedureCOO,
final String title,
final LocalDate date,
Expand All @@ -36,8 +39,9 @@ public String createDocument(

final Document document = new Document(procedureCOO, title, date, type, contents);

return createDocumentOutPort.createDocument(document, user);
String documentCoo = createDocumentOutPort.createDocument(document, user);
List<String> contentCoos = listContentOutPort.listContentCoos(documentCoo, user);

return new DocumentResponse(documentCoo, contentCoos);
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package de.muenchen.oss.digiwf.dms.integration.application.usecase;

import de.muenchen.oss.digiwf.dms.integration.application.port.in.UpdateDocumentInPort;
import de.muenchen.oss.digiwf.dms.integration.application.port.out.ListContentOutPort;
import de.muenchen.oss.digiwf.dms.integration.application.port.out.LoadFileOutPort;
import de.muenchen.oss.digiwf.dms.integration.application.port.out.UpdateDocumentOutPort;
import de.muenchen.oss.digiwf.dms.integration.domain.Content;
import de.muenchen.oss.digiwf.dms.integration.domain.DocumentResponse;
import de.muenchen.oss.digiwf.dms.integration.domain.DocumentType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
Expand All @@ -15,11 +17,12 @@
public class UpdateDocumentUseCase implements UpdateDocumentInPort {

private final UpdateDocumentOutPort updateDocumentOutPort;
private final ListContentOutPort listContentOutPort;

private final LoadFileOutPort loadFileOutPort;

@Override
public void updateDocument(
public DocumentResponse updateDocument(
final String documentCOO,
final String user,
final DocumentType type,
Expand All @@ -31,7 +34,8 @@ public void updateDocument(
final List<Content> contents = loadFileOutPort.loadFiles(filepaths, fileContext, processDefinition);

updateDocumentOutPort.updateDocument(documentCOO, type, contents, user);

List<String> contentCoos = listContentOutPort.listContentCoos(documentCOO, user);
return new DocumentResponse(documentCOO, contentCoos);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.muenchen.oss.digiwf.dms.integration.domain;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

@Data
@AllArgsConstructor
public class DocumentResponse {
private String documentCoo;
private List<String> contentCoos;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.muenchen.oss.digiwf.dms.integration.adapter.in;

import de.muenchen.oss.digiwf.dms.integration.domain.DocumentResponse;
import de.muenchen.oss.digiwf.dms.integration.domain.DocumentType;
import de.muenchen.oss.digiwf.message.process.api.error.IncidentError;
import jakarta.validation.ValidationException;
Expand All @@ -13,6 +14,7 @@
import org.springframework.messaging.MessageHeaders;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

import static de.muenchen.oss.digiwf.message.common.MessageConstants.DIGIWF_PROCESS_INSTANCE_ID;
Expand Down Expand Up @@ -45,7 +47,7 @@ void setup() {
createDocumentDto.getFilepathsAsList(),
createDocumentDto.getFileContext(),
processDefinitionId))
.thenReturn("documentCOO");
.thenReturn(new DocumentResponse("documentCOO", List.of("contentCoo1")));

this.message = new Message<>() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.muenchen.oss.digiwf.dms.integration.adapter.in;

import de.muenchen.oss.digiwf.dms.integration.domain.DocumentResponse;
import de.muenchen.oss.digiwf.dms.integration.domain.DocumentType;
import de.muenchen.oss.digiwf.message.process.api.error.IncidentError;
import jakarta.validation.ValidationException;
Expand All @@ -12,6 +13,7 @@
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;

import java.util.List;
import java.util.Map;

import static de.muenchen.oss.digiwf.message.common.MessageConstants.DIGIWF_PROCESS_INSTANCE_ID;
Expand All @@ -33,7 +35,7 @@ class UpdateDocumentMessageProcessorTest extends MessageProcessorTestBase {
@BeforeEach
void setup() {
setupBase();
Mockito.doNothing().when(updateDocumentInPortMock).updateDocument(
Mockito.doReturn(new DocumentResponse("documentCoo", List.of("contentCoo1"))).when(updateDocumentInPortMock).updateDocument(
updateDocumentDto.getDocumentCoo(),
updateDocumentDto.getUser(),
DocumentType.valueOf(updateDocumentDto.getType()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,31 @@ void execute_cancelObject_request() {
fabasoftAdapter.cancelObject("objectCoo", "user");
}

@Test
void execute_list_files() {
val file1 = new LHMBAI151700GIObjectType();
file1.setLHMBAI151700Objaddress("contentCoo1");
file1.setLHMBAI151700Objname("File-Name");
val content = new ArrayOfLHMBAI151700GIObjectType();
content.getLHMBAI151700GIObjectType().add(file1);

val response = new ReadDocumentGIObjectsResponse();
response.setStatus(0);
response.setGiobjecttype(content);

DigiwfWiremockWsdlUtility.stubOperation(
"ReadDocumentGIObjects",
CancelObjectGI.class, (u) -> true,
response);

val contentCoos = fabasoftAdapter.listContentCoos("coo1", "user");

val expectedCoos = List.of("contentCoo1");

assertThat(contentCoos.size()).isEqualTo(1);
assertEquals(expectedCoos, contentCoos);
}

@Test
void execute_read_files() {
val content = new LHMBAI151700GIAttachmentType();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package de.muenchen.oss.digiwf.dms.integration.application.usecase;

import de.muenchen.oss.digiwf.dms.integration.application.port.out.CreateDocumentOutPort;
import de.muenchen.oss.digiwf.dms.integration.application.port.out.ListContentOutPort;
import de.muenchen.oss.digiwf.dms.integration.application.port.out.LoadFileOutPort;
import de.muenchen.oss.digiwf.dms.integration.domain.Content;
import de.muenchen.oss.digiwf.dms.integration.domain.Document;
import de.muenchen.oss.digiwf.dms.integration.domain.DocumentResponse;
import de.muenchen.oss.digiwf.dms.integration.domain.DocumentType;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

Expand All @@ -19,27 +22,31 @@ class CreateDocumentUseCaseTest {

private final CreateDocumentOutPort createDocumentOutPort = mock(CreateDocumentOutPort.class);

private final CreateDocumentUseCase createDocumentUseCase = new CreateDocumentUseCase(createDocumentOutPort, loadFileOutPort);
private final ListContentOutPort listContentOutPort = mock(ListContentOutPort.class);

private final CreateDocumentUseCase createDocumentUseCase = new CreateDocumentUseCase(createDocumentOutPort, loadFileOutPort, listContentOutPort);

@Test
void createDocument() {

Content content = new Content("extension", "name", "content".getBytes());

List<String> filepaths = List.of("path/content.pdf");
LocalDate testDate = LocalDate.parse("2023-12-01");
String docCoo = "documentCOO";
String user = "user";
List<String> fileCoos = List.of("contentCoo1", "contentCoo2");

when(this.loadFileOutPort.loadFiles(any(), any(), any())).thenReturn(List.of(content));
when(this.createDocumentOutPort.createDocument(any(), any())).thenReturn(docCoo);
when(this.listContentOutPort.listContentCoos(docCoo, user)).thenReturn(fileCoos);

when(this.createDocumentOutPort.createDocument(any(), any())).thenReturn("documentCOO");
LocalDate testDate = LocalDate.parse("2023-12-01");

createDocumentUseCase.createDocument("procedureCOO", "title", testDate, "user", DocumentType.EINGEHEND, filepaths, "filecontext",
DocumentResponse documentResponse = createDocumentUseCase.createDocument("procedureCOO", "title", testDate, "user", DocumentType.EINGEHEND, filepaths, "filecontext",
"processDefinitionId");

assertEquals(docCoo, documentResponse.getDocumentCoo());
assertEquals(fileCoos, documentResponse.getContentCoos());
verify(this.loadFileOutPort, times(1)).loadFiles(filepaths, "filecontext", "processDefinitionId");

verify(this.createDocumentOutPort, times(1)).createDocument(new Document("procedureCOO", "title", testDate, DocumentType.EINGEHEND, List.of(content)),
"user");

user);
verify(this.listContentOutPort, times(1)).listContentCoos(docCoo, user);
}
}
Loading
Loading