Skip to content

Commit

Permalink
- Revised all module common-jms.
Browse files Browse the repository at this point in the history
- Created the BroadcastController on module common-web-notification.
- Created the module common-web-notification-client.
- Renamed AbstractEntity.kt to AbstractIdentity.kt.
  • Loading branch information
desiderati committed Jul 5, 2024
1 parent a6c3031 commit fe1b371
Show file tree
Hide file tree
Showing 77 changed files with 963 additions and 238 deletions.
36 changes: 19 additions & 17 deletions .editorconfig

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Build with Maven
# mvn -B: Batch mode causes Maven to not display "Progress: 125/150kB" style lines when running.
# Must be 'clean package', instead of 'clean test', otherwise this error will occur: "Artifact has not been packaged yet!"
run: mvn -B clean package
run: mvn -P generate-openapi-sources -B clean package

- name: Create Tag Version
run: mvn -B scm:tag -Dusername=${{ github.actor }} -Dpassword=${{ github.token }}
Expand Down
15 changes: 15 additions & 0 deletions .runconfig/common-web-notification.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="common-web-notification" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
<module name="common-web-notification" />
<option name="SPRING_BOOT_MAIN_CLASS" value="io.herd.common.web.notification.WebTempApplication" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="io.herd.common.web.notification.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Commons Herd.io
---------------

[![Build Status](https://github.com/desiderati/commons/workflows/Build/badge.svg)](https://github.com/desiderati/commons/actions)
[![Version](https://img.shields.io/badge/Version-3.3.0.RC2-red.svg)](https://github.com/desiderati/commons/releases)
[![Version](https://img.shields.io/badge/Version-3.3.0.RC3-red.svg)](https://github.com/desiderati/commons/releases)
[![GitHub Stars](https://img.shields.io/github/stars/desiderati/commons.svg?label=GitHub%20Stars)](https://github.com/desiderati/commons/)
[![LICENSE](https://img.shields.io/badge/License-MIT-lightgrey.svg)](https://github.com/desiderati/commons/blob/master/LICENSE)

Expand All @@ -24,15 +24,15 @@ Changelog

All project changes will be documented in this file.

#### [3.3.0.RC2] - 2024-01-12
#### [3.3.0.RC3] - 2024-01-12
- Added support to retrieve the authorities passed by the delegated authentication provider.
- Added support for pre/post authorizations on GraphQL calls.
- Added Hamkrest and Spek as test dependencies.
- Added initial support for ArrowKt.
- Added the pageable functionality for GraphQL.
- Removed dependency with org.reflections.
- Updated some dependency versions.
- Update the copyrigth.
- Update the copyright.

#### [3.2.1.RELEASE] - 2023-12-13
- Added support to create request scoped beans within async threads.
Expand Down Expand Up @@ -369,8 +369,8 @@ All project changes will be documented in this file.
- Creation of CPF/CNPJ field validations.
- Creation of the generic exception handling functionality. (**ExceptionHandlingController**)
- Creation of JPA repositories to handle null method parameters (_Null-Safe Parameters_), including MongoDB.
- Creation of **AbstractRepository** class to assist in the creation of personalized data repositories.
- Creation of **AbstractPersistableIdentity** class to assist in the creation of JPA entities.
- Creation of **AbstractRepository** class to help in the creation of personalized data repositories.
- Creation of **AbstractPersistableIdentity** class to help in the creation of JPA entities.
- Creation of the functionality responsible for defining the name strategy to use with databases. (_Naming Strategy_)
- Creation of classes to use with automated tests.
- Added support for internationalization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ package io.herd.common.data.jpa
import org.springframework.data.util.ProxyUtils
import java.io.Serializable

abstract class AbstractEntity<I : Serializable> : Identity<I> {
abstract class AbstractIdentity<I : Serializable> : Identity<I> {

@Override
abstract override fun getId() : I?
abstract override fun getId(): I?

@Override
override fun equals(other: Any?): Boolean {
Expand All @@ -36,11 +36,11 @@ abstract class AbstractEntity<I : Serializable> : Identity<I> {
return true
}

if (javaClass != ProxyUtils.getUserClass(other) && other !is AbstractEntity<*>) {
if (javaClass != ProxyUtils.getUserClass(other) && other !is AbstractIdentity<*>) {
return false
}

val that = other as AbstractEntity<*>
val that = other as AbstractIdentity<*>
return this.id == that.id
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
*/
package io.herd.common.data.jpa;

import jakarta.persistence.*;
import org.springframework.data.domain.Persistable;
import org.springframework.data.jpa.domain.AbstractPersistable;

import jakarta.persistence.*;
import java.io.Serializable;

/**
Expand All @@ -35,7 +35,7 @@
*/
@MappedSuperclass
@SuppressWarnings("unused")
public abstract class AbstractPersistableIdentity<I extends Serializable> extends AbstractEntity<I> implements Persistable<I>, Identity<I> {
public abstract class AbstractPersistableIdentity<I extends Serializable> extends AbstractIdentity<I> implements Persistable<I>, Identity<I> {

public AbstractPersistableIdentity() {
this(null);
Expand All @@ -54,7 +54,7 @@ public final I getId() {
return id;
}

protected final void setId(final I id) {
protected void setId(final I id) {
this.id = id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class MultiTenantContext {
private static String defaultTenant;

@Autowired
@SuppressWarnings("squid:S3010") // We may ignore the error because it will have only one instance by application context.
@SuppressWarnings("squid:S3010")
// We may ignore the error because it will have only one instance by application context.
public MultiTenantContext(@Value("${app.database.multitenant.default-tenant:public}") String defaultTenant) {
MultiTenantContext.defaultTenant = defaultTenant;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class AbstractEntityTest {
}
}

internal open class ClassePai(private var id: Long? = null) : AbstractEntity<Long>() {
internal open class ClassePai(private var id: Long? = null) : AbstractIdentity<Long>() {
override fun getId(): Long? {
return id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
{
"name": "google.captcha.secret-key",
"description": "Google Captcha service secret key.",
"type": "java.lang.String",
"defaultValue": "/google-calendar-api-secret.json"
"type": "java.lang.String"
}
]
}
6 changes: 3 additions & 3 deletions common-jms/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Support for JMS Queues
----------------------

It will be necessary to copy the file `jms.properties` contained in the directory `/src/main/resources`
of this project, to your application's `/src/main/resources` directory, changing the values
It will be necessary to copy the file `jms.properties` contained in the directory `/src/main/resources`
of this project, to your application's `/src/main/resources` directory, changing the values
of its properties according to the necessity.
Only copy this properties file, in case there is a change in the properties.
Only copy this properties file, in case there is a change in the properties.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2024 - Felipe Desiderati
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package io.herd.common.jms;

import java.util.UUID;

@SuppressWarnings("unused")
public abstract class AbstractAsyncMessage implements AsyncMessage {

private final UUID msgId;

public AbstractAsyncMessage() {
this.msgId = UUID.randomUUID();
}

@Override
public UUID getMsgId() {
return msgId;
}

@Override
public String toString() {
return "AbstractAsyncMessage{mgId=" + msgId + "}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2024 - Felipe Desiderati
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package io.herd.common.jms;

import io.herd.common.exception.ApplicationException;
import io.herd.common.jms.configuration.JmsAutoConfiguration;
import jakarta.jms.Message;
import jakarta.validation.ConstraintViolationException;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.annotation.JmsListener;

/**
* {@link jakarta.jms.MessageListener} responsible for reading messages sent to the standard queue.
*
* @see JmsAutoConfiguration#queue(String)
*/
@Slf4j
public abstract class AbstractAsyncMessageListener<M extends AsyncMessage> {

@SneakyThrows
@JmsListener(destination = "${jms.default-queue.name}")
public void onMessage(Message jmsMessage, M message) {
try {
log.info("Message '{}' received!", message.getMsgId());
log.debug("{}", jmsMessage);
receive(message);
log.info("Message '{}' received and processed with success!", message.getMsgId());
jmsMessage.acknowledge();

} catch (ApplicationException applicationException) {
// It means is an application (business) exception and there's nothing else to do about it.
handleApplicationException(jmsMessage, message, applicationException);

} catch (ConstraintViolationException constraintViolationException) {
// Thrown when used the @{link jakarta.validation.Valid} annotation.
StringBuilder validationErrorsMsg = new StringBuilder("Constraint Violations:");
constraintViolationException.getConstraintViolations().forEach(
constraintViolation -> validationErrorsMsg
.append(System.lineSeparator())
.append(constraintViolation.getPropertyPath())
.append(":")
.append(constraintViolation.getMessage())
);
handleApplicationException(jmsMessage, message, new ApplicationException(validationErrorsMsg.toString()));

} catch (Throwable throwable) {
throw new JmsApplicationException(jmsMessage, throwable.getMessage(), throwable);
}
}

/**
* Method responsible for processing the message received from the queue.
*
* @param message The message received from the queue.
* @throws Exception If any error occurs during the processing of the message.
*/
protected abstract void receive(M message) throws Exception;

/**
* Handles an application (business) exception that occurred while processing a message.
*
* @param jmsMessage The JMS message that triggered the exception.
* @param message The message being processed when the exception occurred.
* @param applicationException The application exception that occurred.
*/
@SuppressWarnings("unused")
protected void handleApplicationException(
Message jmsMessage,
M message,
ApplicationException applicationException
) {
log.error("Error while processing message '{}': ", message.getMsgId(), applicationException);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@
*/
package io.herd.common.jms;

import lombok.Getter;

import java.io.Serializable;
import java.util.UUID;

@Getter
public abstract class Message {
public interface AsyncMessage extends Serializable {

private final UUID id;
UUID getMsgId();

public Message() {
id = UUID.randomUUID();
}
}
Loading

0 comments on commit fe1b371

Please sign in to comment.