Skip to content

Commit

Permalink
Feature/pmd integrations (#208)
Browse files Browse the repository at this point in the history
* ➕ gateway add pmd

* ➕ gateway add spotbugs

* 🚨 gateway fix pmd and spotbugs findings

* 🚨 gateway fix pmd findings

* 👷 ci whitelist spotbugs license

* ➕ integrations add pmd and spotbugs

* 🚨 integrations fix pmd and spotbugs findings

* 🚨 s3 fix pmd and spotbugs findings

* 🚨 mail fix pmd findings

* 🐛 s3 integration fix imports

* 🎨 integrations format with spotless

* 🚨 s3 fix pmd warnings

* 🚨 mail fix pmd warnings

* 🚨 dms fix pmd warnings

* 🚨 dms fix pmd warnings

* 🚨 dms fix pmd warnings

* 🚨 dms fix pmd warnings

* 🚨 dms fix pmd warnings

* 🎨 dms spotless format

* ➖ integrations rm spotbugs

* 🚨 dms fix pmd warnings

* ⬆️ integrations use pmd module and pmd 3.26

* ⬆️ integrations pmd use new junit warning names

* 🚨 integrations suppress instead of exclude warnings

* ⬆️ integrations use pmd conf v1.0.1

* ♻️ pom reorder pmd module

* ♻️ s3 refactor test instead suppressing

* ♻️ s3 use import for assert methods

* ♻️ integrations supress serial for exceptions

* ♻️ dms use english and use assert instead of suppressing for test

* 🔥 dms rm unnecessary supress

* ♻️ dms use assert instead of suppressing for test

* 🔥 dms rm unnecessary supress

* ✏️ dms fix class name typo

* ♻️ integrations supress serial

* 🎨 format spotless

* ♻️ dms refactor exception encapsulation

* 💚 codeql disable js

* ♻️ dms refactor exception encapsulation fix test

---------

Co-authored-by: Tobias Stadler <28538704+devtobi@users.noreply.github.com>
  • Loading branch information
simonhir and devtobi authored Nov 8, 2024
1 parent e5fe637 commit ce13f94
Show file tree
Hide file tree
Showing 145 changed files with 1,056 additions and 1,063 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ jobs:
uses: it-at-m/.github/.github/workflows/codeql.yml@main
with:
analyze-java: true
analyze-javascript-typescript-vue: true
analyze-javascript-typescript-vue: false
java-build-paths: "['./refarch-gateway','./refarch-integrations','./refarch-tools/refarch-java-tools']"
2 changes: 1 addition & 1 deletion refarch-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

<!-- Core Frameworks -->
<spring-cloud.version>2023.0.3</spring-cloud.version>
<refarch-tools.version>1.0.0</refarch-tools.version>

<!-- Logging -->
<logstash-logback-encoder.version>8.0</logstash-logback-encoder.version>
Expand All @@ -46,6 +45,7 @@

<!-- Utility -->
<apache-commons-lang.version>3.17.0</apache-commons-lang.version>
<refarch-tools.version>1.0.0</refarch-tools.version>

<!-- Additional required dependencies -->
<hazelcast.version>5.5.0</hazelcast.version>
Expand Down
39 changes: 39 additions & 0 deletions refarch-integrations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<!-- Linting & Formatting -->
<spotless-maven-plugin.version>2.34.0</spotless-maven-plugin.version>
<itm-java-codeformat.version>1.0.10</itm-java-codeformat.version>
<pmd-maven-plugin.version>3.26.0</pmd-maven-plugin.version>

<!-- Release -->
<central-publishing-maven-plugin.version>0.5.0</central-publishing-maven-plugin.version>
Expand All @@ -50,6 +51,7 @@
<!-- Utility -->
<mapstruct.version>1.6.2</mapstruct.version>
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
<refarch-tools.version>1.0.1</refarch-tools.version>

<!-- Additional required dependencies -->
<springdoc-openapi.version>2.6.0</springdoc-openapi.version>
Expand Down Expand Up @@ -245,6 +247,43 @@
</execution>
</executions>
</plugin>

<!-- Linting -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${pmd-maven-plugin.version}</version>
<configuration>
<minimumTokens>100</minimumTokens>
<targetJdk>${java.version}</targetJdk>
<printFailingErrors>true</printFailingErrors>
<linkXRef>false</linkXRef>
<includeTests>true</includeTests>
<excludeRoots>
<excludeRoot>target/generated</excludeRoot>
<excludeRoot>target/generated-sources</excludeRoot>
<excludeRoot>target/generated-test-sources</excludeRoot>
</excludeRoots>
<rulesets>
<ruleset>refarch-pmd-ruleset.xml</ruleset>
</rulesets>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>de.muenchen.refarch.tools</groupId>
<artifactId>refarch-pmd</artifactId>
<version>${refarch-tools.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import de.muenchen.refarch.integration.dms.domain.exception.DmsException;

public class DMSErrorHandler {
public void handleError(int code, String errorMessage) throws DmsException {
public void handleError(final int code, final String errorMessage) throws DmsException {

final DMSStatusCode statusCode = DMSStatusCode.byCode(code);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* All known object classes to provide soap requests with.
*/
@SuppressWarnings({ "PMD.ExcessivePublicCount", "PMD.FieldNamingConventions" })
public enum DMSObjectClass {

Fileplan("COOELAK@1.1001:Fileplan"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum DMSStatusCode {
}

public static DMSStatusCode byCode(final int code) {
for (final DMSStatusCode status : DMSStatusCode.values()) {
for (final DMSStatusCode status : values()) {
if (status.statuscode == code) {
return status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadContentObjectGI;
import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadContentObjectGIResponse;
import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadContentObjectMetaDataGI;
import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadContentObjectMetaDataGIResponse;
import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadDocumentGIObjects;
import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadDocumentGIObjectsResponse;
import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadMetadataObjectGI;
import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.ReadMetadataObjectGIResponse;
import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.SearchObjNameGI;
import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.SearchObjNameGIResponse;
import com.fabasoft.schemas.websvc.lhmbai_15_1700_giwsd.UpdateIncomingGI;
Expand Down Expand Up @@ -57,7 +59,6 @@
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.lang3.StringUtils;
import org.springframework.lang.NonNull;

Expand All @@ -68,6 +69,7 @@

@Slf4j
@RequiredArgsConstructor
@SuppressWarnings({ "PMD.UseObjectForClearerAPI", "PMD.CouplingBetweenObjects" })
public class FabasoftAdapter implements
CreateFileOutPort,
CreateProcedureOutPort,
Expand All @@ -87,7 +89,7 @@ public class FabasoftAdapter implements
private final DMSErrorHandler dmsErrorHandler = new DMSErrorHandler();

@Override
public String createFile(File file, String user) throws DmsException {
public String createFile(final File file, final String user) throws DmsException {
//logging for dms team
log.info("calling CreateFileGI Userlogin: {} Apentry: {} Filesubj: {} Shortname: {} Apentrysearch: true", user, file.apentryCOO(), file.title(),
file.title());
Expand All @@ -107,7 +109,7 @@ public String createFile(File file, String user) throws DmsException {
}

@Override
public Procedure createProcedure(Procedure procedure, String user) throws DmsException {
public Procedure createProcedure(final Procedure procedure, final String user) throws DmsException {
log.info("calling CreateProcedureGI: {}", procedure.toString());

final CreateProcedureGI request = new CreateProcedureGI();
Expand Down Expand Up @@ -311,7 +313,7 @@ private void updateInternalDocument(final String documentCOO, final List<Content
}

@Override
public void depositObject(String objectCoo, String user) throws DmsException {
public void depositObject(final String objectCoo, final String user) throws DmsException {
log.info("calling DepositObject: {}", objectCoo);

final DepositObjectGI request = new DepositObjectGI();
Expand Down Expand Up @@ -347,13 +349,13 @@ public void cancelObject(final String objectCoo, final String user) throws DmsEx
}

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

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

return response.getGiobjecttype().getLHMBAI151700GIObjectType().stream()
Expand All @@ -365,28 +367,28 @@ public List<String> listContentCoos(@NonNull String documentCoo, @NonNull final
public List<Content> readContent(final List<String> coos, final String user) throws DmsException {
final List<Content> files = new ArrayList<>();

for (val coo : coos) {
val request = new ReadContentObjectGI();
for (final String coo : coos) {
final ReadContentObjectGI request = new ReadContentObjectGI();
request.setUserlogin(user);
request.setBusinessapp(this.properties.getBusinessapp());
request.setObjaddress(coo);
val response = this.wsClient.readContentObjectGI(request);
final ReadContentObjectGIResponse response = this.wsClient.readContentObjectGI(request);
dmsErrorHandler.handleError(response.getStatus(), response.getErrormessage());
files.add(this.map(response));
}

return files;
}

private Content map(ReadContentObjectGIResponse response) {
private Content map(final ReadContentObjectGIResponse response) {
return new Content(
response.getGiattachmenttype().getLHMBAI151700Fileextension(),
response.getGiattachmenttype().getLHMBAI151700Filename(),
response.getGiattachmenttype().getLHMBAI151700Filecontent());
}

@Override
public List<String> searchFile(String searchString, String user, String reference, String value) throws DmsException {
public List<String> searchFile(final String searchString, final String user, final String reference, final String value) throws DmsException {
return this.searchObject(searchString, DMSObjectClass.Sachakte, user, reference, value).stream()
.map(LHMBAI151700GIObjectType::getLHMBAI151700Objaddress)
.toList();
Expand All @@ -403,11 +405,11 @@ public List<String> searchSubjectArea(final String searchString, final String us
public Metadata readMetadata(final String coo, final String username) throws DmsException {
log.info("calling ReadMetadataObjectGI Userlogin: {} COO: {}", username, coo);

val request = new ReadMetadataObjectGI();
final ReadMetadataObjectGI request = new ReadMetadataObjectGI();
request.setObjaddress(coo);
request.setBusinessapp(this.properties.getBusinessapp());
request.setUserlogin(username);
val response = this.wsClient.readMetadataObjectGI(request);
final ReadMetadataObjectGIResponse response = this.wsClient.readMetadataObjectGI(request);

dmsErrorHandler.handleError(response.getStatus(), response.getErrormessage());

Expand All @@ -421,11 +423,11 @@ public Metadata readMetadata(final String coo, final String username) throws Dms
public Metadata readContentMetadata(final String coo, final String username) throws DmsException {
log.info("calling ReadContentObjectMetaDataGI Userlogin: {} COO: {}", username, coo);

val request = new ReadContentObjectMetaDataGI();
final ReadContentObjectMetaDataGI request = new ReadContentObjectMetaDataGI();
request.setObjaddress(coo);
request.setBusinessapp(this.properties.getBusinessapp());
request.setUserlogin(username);
val response = this.wsClient.readContentObjectMetaDataGI(request);
final ReadContentObjectMetaDataGIResponse response = this.wsClient.readContentObjectMetaDataGI(request);

dmsErrorHandler.handleError(response.getStatus(), response.getErrormessage());

Expand Down Expand Up @@ -472,8 +474,12 @@ private List<LHMBAI151700GIObjectType> searchObject(final String searchString, f
params.setBusinessapp(this.properties.getBusinessapp());
params.setObjclass(dmsObjectClass.getName());
params.setSearchstring(searchString);
if (Objects.nonNull(reference)) params.setReference(reference);
if (Objects.nonNull(value)) params.setValue(value);
if (Objects.nonNull(reference)) {
params.setReference(reference);
}
if (Objects.nonNull(value)) {
params.setValue(value);
}

final SearchObjNameGIResponse response = this.wsClient.searchObjNameGI(params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.Set;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.io.FilenameUtils;
import org.springframework.util.unit.DataSize;

Expand All @@ -37,7 +36,7 @@ public class S3Adapter implements LoadFileOutPort, TransferContentOutPort {
public List<Content> loadFiles(final List<String> filePaths) throws DocumentStorageException {
validateFileSizes(filePaths);
final List<Content> contents = new ArrayList<>();
for (String path : filePaths) {
for (final String path : filePaths) {
if (path.endsWith("/")) {
contents.addAll(getFilesFromFolder(path));
} else {
Expand All @@ -64,15 +63,16 @@ private void validateFileSizes(final List<String> filePaths) throws DocumentStor

// Validate total batch size
final DataSize totalFileSize = fileService.getTotalBatchSize(fileSizesWithPaths);
if (!fileService.isValidBatchSize(totalFileSize))
if (!fileService.isValidBatchSize(totalFileSize)) {
throw new FileSizeValidationException(String.format("Batch size of %d MB is too large. Allowed are %d MB.",
totalFileSize.toMegabytes(), fileService.getMaxBatchSize().toMegabytes()));
}
}

private Map<String, Long> getFileSizesWithPaths(final List<String> filePaths) throws DocumentStorageException {
Map<String, Long> map = new HashMap<>();
for (String path : filePaths) {
for (Map.Entry<String, Long> stringLongEntry : getFileSizeForPath(path).entrySet()) {
final Map<String, Long> map = new HashMap<>();
for (final String path : filePaths) {
for (final Map.Entry<String, Long> stringLongEntry : getFileSizeForPath(path).entrySet()) {
if (map.put(stringLongEntry.getKey(), stringLongEntry.getValue()) != null) {
throw new IllegalStateException("Duplicate key");
}
Expand All @@ -93,7 +93,7 @@ private Map<String, Long> getSizesInFolderRecursively(final String folderPath) t
try {
return Objects.requireNonNull(documentStorageFolderRepository
.getAllFileSizesInFolderRecursively(folderPath));
} catch (final DocumentStorageException | DocumentStorageServerErrorException | DocumentStorageClientErrorException e) {
} catch (final DocumentStorageServerErrorException | DocumentStorageClientErrorException e) {
throw new DocumentStorageException("Metadata of a folder could not be loaded from url: " + folderPath, e);
}
}
Expand All @@ -102,7 +102,7 @@ private long getFileSize(final String filePath) throws DocumentStorageException
try {
return Objects.requireNonNull(documentStorageFileRepository
.getFileSize(filePath));
} catch (final DocumentStorageException | DocumentStorageServerErrorException | DocumentStorageClientErrorException e) {
} catch (final DocumentStorageServerErrorException | DocumentStorageClientErrorException e) {
throw new DocumentStorageException("Metadata of a folder could not be loaded from url: " + filePath, e);
}
}
Expand All @@ -112,12 +112,14 @@ private List<Content> getFilesFromFolder(final String folderPath) throws Documen
final List<Content> contents = new ArrayList<>();
final Set<String> filepath;
filepath = documentStorageFolderRepository.getAllFilesInFolderRecursively(folderPath);
if (Objects.isNull(filepath)) throw new DocumentStorageException("An folder could not be loaded from url: " + folderPath);
for (String file : filepath) {
if (Objects.isNull(filepath)) {
throw new DocumentStorageException("An folder could not be loaded from url: " + folderPath);
}
for (final String file : filepath) {
contents.add(getFile(file));
}
return contents;
} catch (final DocumentStorageException | DocumentStorageServerErrorException | DocumentStorageClientErrorException e) {
} catch (final DocumentStorageServerErrorException | DocumentStorageClientErrorException e) {
throw new DocumentStorageException("An folder could not be loaded from url: " + folderPath, e);
}
}
Expand All @@ -129,22 +131,23 @@ private Content getFile(final String filePath) throws DocumentStorageException {
final String mimeType = fileService.detectFileType(bytes);
final String filename = FilenameUtils.getBaseName(filePath);

if (!fileService.isSupported(mimeType))
if (!fileService.isSupported(mimeType)) {
throw new FileTypeValidationException("The type of this file is not supported: " + filePath);
}

return new Content(fileService.getFileExtension(mimeType), filename, bytes);
} catch (final DocumentStorageException | DocumentStorageServerErrorException | DocumentStorageClientErrorException e) {
} catch (final DocumentStorageServerErrorException | DocumentStorageClientErrorException e) {
throw new DocumentStorageException("An file could not be loaded from url: " + filePath, e);
}
}

@Override
public void transferContent(final List<Content> content, final String filepath) throws DocumentStorageException {
for (val file : content) {
for (final Content file : content) {
try {
val fullFilePath = (filepath + "/" + file.name() + "." + file.extension()).replace("//", "/");
final String fullFilePath = (filepath + "/" + file.name() + "." + file.extension()).replace("//", "/");
this.documentStorageFileRepository.saveFile(fullFilePath, file.content(), 1);
} catch (Exception e) {
} catch (final Exception e) {
throw new DocumentStorageException("An file could not be saved to path: " + filepath, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

public interface CancelObjectInPort {

void cancelObject(@NotBlank final String objectCoo, @NotBlank final String user) throws DmsException;
void cancelObject(@NotBlank String objectCoo, @NotBlank String user) throws DmsException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public interface CreateDocumentInPort {

DocumentResponse createDocument(final String procedureCOO, final String title, final LocalDate date, final String user, DocumentType type,
final List<String> filepaths) throws DmsException, DocumentStorageException;
DocumentResponse createDocument(String procedureCOO, String title, LocalDate date, String user, DocumentType type,
List<String> filepaths) throws DmsException, DocumentStorageException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

public interface CreateFileInPort {

String createFile(@NotBlank final String titel, @NotBlank final String apentryCOO, @NotBlank final String user) throws DmsException;
String createFile(@NotBlank String titel, @NotBlank String apentryCOO, @NotBlank String user) throws DmsException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import de.muenchen.refarch.integration.dms.domain.model.Procedure;
import jakarta.validation.constraints.NotBlank;

@SuppressWarnings("PMD.UseObjectForClearerAPI")
public interface CreateProcedureInPort {

Procedure createProcedure(@NotBlank final String titel, @NotBlank final String fileCOO, final String fileSubj, @NotBlank final String user)
Procedure createProcedure(@NotBlank String titel, @NotBlank String fileCOO, String fileSubj, @NotBlank String user)
throws DmsException;

}
Loading

0 comments on commit ce13f94

Please sign in to comment.