Merge branch 'master' into feature_enable_push_in_deployment_view
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.model;
|
||||
|
||||
/**
|
||||
* Interface for the entity interceptor lifecycle.
|
||||
*/
|
||||
public interface EntityInterceptor {
|
||||
|
||||
/**
|
||||
* Callback for the {@link @PrePersist} lifecycle event.
|
||||
*
|
||||
* @param entity
|
||||
* the model entity
|
||||
*/
|
||||
default void prePersist(final Object entity) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback for the {@link @PostPersist} lifecycle event.
|
||||
*
|
||||
* @param entity
|
||||
* the model entity
|
||||
*/
|
||||
default void postPersist(final Object entity) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback for the {@link @PostRemove} lifecycle event.
|
||||
*
|
||||
* @param entity
|
||||
* the model entity
|
||||
*/
|
||||
default void postRemove(final Object entity) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback for the {@link @PreRemove} lifecycle event.
|
||||
*
|
||||
* @param entity
|
||||
* the model entity
|
||||
*/
|
||||
default void preRemove(final Object entity) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback for the {@link @PostLoad} lifecycle event.
|
||||
*
|
||||
* @param entity
|
||||
* the model entity
|
||||
*/
|
||||
default void postLoad(final Object entity) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback for the {@link @PreUpdate} lifecycle event.
|
||||
*
|
||||
* @param entity
|
||||
* the model entity
|
||||
*/
|
||||
default void preUpdate(final Object entity) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback for the {@link @PostUpdate} lifecycle event.
|
||||
*
|
||||
* @param entity
|
||||
* the model entity
|
||||
*/
|
||||
default void postUpdate(final Object entity) {
|
||||
};
|
||||
|
||||
}
|
||||
@@ -46,6 +46,7 @@ import org.eclipse.hawkbit.repository.jpa.aspects.ExceptionMappingAspectHandler;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.MultiTenantJpaTransactionManager;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.CacheManagerHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemManagementHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder;
|
||||
@@ -144,6 +145,14 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
return SecurityTokenGeneratorHolder.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the singleton instance of the {@link EntityInterceptorHolder}
|
||||
*/
|
||||
@Bean
|
||||
public EntityInterceptorHolder entityInterceptorHolder() {
|
||||
return EntityInterceptorHolder.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the singleton instance of the {@link CacheManagerHolder}
|
||||
*/
|
||||
|
||||
@@ -31,7 +31,8 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
*/
|
||||
@MappedSuperclass
|
||||
@Access(AccessType.FIELD)
|
||||
@EntityListeners({ AuditingEntityListener.class, CacheFieldEntityListener.class, EntityPropertyChangeListener.class })
|
||||
@EntityListeners({ AuditingEntityListener.class, CacheFieldEntityListener.class, EntityPropertyChangeListener.class,
|
||||
EntityInterceptorListener.class })
|
||||
public abstract class AbstractJpaBaseEntity implements BaseEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.model;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.persistence.PostLoad;
|
||||
import javax.persistence.PostPersist;
|
||||
import javax.persistence.PostRemove;
|
||||
import javax.persistence.PostUpdate;
|
||||
import javax.persistence.PrePersist;
|
||||
import javax.persistence.PreRemove;
|
||||
import javax.persistence.PreUpdate;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder;
|
||||
import org.eclipse.hawkbit.repository.model.EntityInterceptor;
|
||||
|
||||
/**
|
||||
* Entity listener which calls the callback's of all registered entity
|
||||
* interceptors.
|
||||
*/
|
||||
public class EntityInterceptorListener {
|
||||
|
||||
@PrePersist
|
||||
protected void prePersist(final Object entity) {
|
||||
notifyAll(interceptor -> interceptor.prePersist(entity));
|
||||
}
|
||||
|
||||
@PostPersist
|
||||
protected void postPersist(final Object entity) {
|
||||
notifyAll(interceptor -> interceptor.postPersist(entity));
|
||||
}
|
||||
|
||||
@PostRemove
|
||||
protected void postRemove(final Object entity) {
|
||||
notifyAll(interceptor -> interceptor.postRemove(entity));
|
||||
}
|
||||
|
||||
@PreRemove
|
||||
protected void preRemove(final Object entity) {
|
||||
notifyAll(interceptor -> interceptor.preRemove(entity));
|
||||
}
|
||||
|
||||
@PostLoad
|
||||
protected void postLoad(final Object entity) {
|
||||
notifyAll(interceptor -> interceptor.postLoad(entity));
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
protected void preUpdate(final Object entity) {
|
||||
notifyAll(interceptor -> interceptor.preUpdate(entity));
|
||||
}
|
||||
|
||||
@PostUpdate
|
||||
protected void postUpdate(final Object entity) {
|
||||
notifyAll(interceptor -> interceptor.postUpdate(entity));
|
||||
}
|
||||
|
||||
private void notifyAll(final Consumer<? super EntityInterceptor> action) {
|
||||
EntityInterceptorHolder.getInstance().getEntityInterceptors().forEach(action);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.model.helper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.EntityInterceptor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* A singleton bean which holds the {@link EntityInterceptor} to have all
|
||||
* interceptors in spring beans.
|
||||
*
|
||||
*/
|
||||
public final class EntityInterceptorHolder {
|
||||
|
||||
private static final EntityInterceptorHolder SINGLETON = new EntityInterceptorHolder();
|
||||
|
||||
@Autowired(required = false)
|
||||
private final List<EntityInterceptor> entityInterceptors = new ArrayList<>();
|
||||
|
||||
private EntityInterceptorHolder() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the entity intreceptor holder singleton instance
|
||||
*/
|
||||
public static EntityInterceptorHolder getInstance() {
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
public List<EntityInterceptor> getEntityInterceptors() {
|
||||
return entityInterceptors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.model;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder;
|
||||
import org.eclipse.hawkbit.repository.model.EntityInterceptor;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.junit.Test;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
* Test the entity listener interceptor.
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Entity Listener Interceptor")
|
||||
public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Override
|
||||
public void after() {
|
||||
EntityInterceptorHolder.getInstance().getEntityInterceptors().clear();
|
||||
super.after();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that the pre persist is called after a entity creation.")
|
||||
public void prePersistIsCalledWhenPersistingATarget() {
|
||||
executePersistAndAssertCallbackResult(new PrePersistEntityListener());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that the post persist is called after a entity creation.")
|
||||
public void postPersistIsCalledWhenPersistingATarget() {
|
||||
executePersistAndAssertCallbackResult(new PostPersistEntityListener());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that the post load is called after a entity is loaded.")
|
||||
public void postLoadIsCalledWhenLoadATarget() {
|
||||
final PostLoadEntityListener postLoadEntityListener = new PostLoadEntityListener();
|
||||
EntityInterceptorHolder.getInstance().getEntityInterceptors().add(postLoadEntityListener);
|
||||
|
||||
final Target targetToBeCreated = entityFactory.generateTarget("targetToBeCreated");
|
||||
|
||||
targetManagement.createTarget(targetToBeCreated);
|
||||
|
||||
final Target loadedTarget = targetManagement.findTargetByControllerID(targetToBeCreated.getControllerId());
|
||||
assertThat(postLoadEntityListener.getEntity()).isNotNull();
|
||||
assertThat(postLoadEntityListener.getEntity()).isEqualTo(loadedTarget);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that the pre update is called after a entity update.")
|
||||
public void preUpdateIsCalledWhenUpdateATarget() {
|
||||
executeUpdateAndAssertCallbackResult(new PreUpdateEntityListener());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that the post update is called after a entity update.")
|
||||
public void postUpdateIsCalledWhenUpdateATarget() {
|
||||
executeUpdateAndAssertCallbackResult(new PostUpdateEntityListener());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that the pre remove is called after a entity deletion.")
|
||||
public void preRemoveIsCalledWhenDeletingATarget() {
|
||||
executeDeleteAndAssertCallbackResult(new PreRemoveEntityListener());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that the post remove is called after a entity deletion.")
|
||||
public void postRemoveIsCalledWhenDeletingATarget() {
|
||||
executeDeleteAndAssertCallbackResult(new PostRemoveEntityListener());
|
||||
}
|
||||
|
||||
private void executePersistAndAssertCallbackResult(final AbstractEntityListener entityInterceptor) {
|
||||
final Target targetToBeCreated = entityFactory.generateTarget("targetToBeCreated");
|
||||
addListenerAndCreateTarget(entityInterceptor, targetToBeCreated);
|
||||
|
||||
assertThat(entityInterceptor.getEntity()).isNotNull();
|
||||
assertThat(entityInterceptor.getEntity()).isEqualTo(targetToBeCreated);
|
||||
}
|
||||
|
||||
private void executeUpdateAndAssertCallbackResult(final AbstractEntityListener entityInterceptor) {
|
||||
Target updateTarget = addListenerAndCreateTarget(entityInterceptor,
|
||||
entityFactory.generateTarget("targetToBeCreated"));
|
||||
updateTarget.setDescription("New");
|
||||
|
||||
updateTarget = targetManagement.updateTarget(updateTarget);
|
||||
|
||||
assertThat(entityInterceptor.getEntity()).isNotNull();
|
||||
assertThat(entityInterceptor.getEntity()).isEqualTo(updateTarget);
|
||||
}
|
||||
|
||||
private void executeDeleteAndAssertCallbackResult(final AbstractEntityListener entityInterceptor) {
|
||||
EntityInterceptorHolder.getInstance().getEntityInterceptors().add(entityInterceptor);
|
||||
final SoftwareModuleType type = softwareManagement
|
||||
.createSoftwareModuleType(entityFactory.generateSoftwareModuleType("test", "test", "test", 1));
|
||||
|
||||
softwareManagement.deleteSoftwareModuleType(type);
|
||||
assertThat(entityInterceptor.getEntity()).isNotNull();
|
||||
assertThat(entityInterceptor.getEntity()).isEqualTo(type);
|
||||
}
|
||||
|
||||
private Target addListenerAndCreateTarget(final AbstractEntityListener entityInterceptor,
|
||||
final Target targetToBeCreated) {
|
||||
EntityInterceptorHolder.getInstance().getEntityInterceptors().add(entityInterceptor);
|
||||
return targetManagement.createTarget(targetToBeCreated);
|
||||
}
|
||||
|
||||
private static abstract class AbstractEntityListener implements EntityInterceptor {
|
||||
|
||||
private Object entity;
|
||||
|
||||
public Object getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void setEntity(final Object entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
}
|
||||
|
||||
private static class PrePersistEntityListener extends AbstractEntityListener {
|
||||
@Override
|
||||
public void prePersist(final Object entity) {
|
||||
setEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
private static class PostPersistEntityListener extends AbstractEntityListener {
|
||||
@Override
|
||||
public void postPersist(final Object entity) {
|
||||
setEntity(entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class PostLoadEntityListener extends AbstractEntityListener {
|
||||
@Override
|
||||
public void postLoad(final Object entity) {
|
||||
setEntity(entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class PreUpdateEntityListener extends AbstractEntityListener {
|
||||
@Override
|
||||
public void preUpdate(final Object entity) {
|
||||
setEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
private static class PostUpdateEntityListener extends AbstractEntityListener {
|
||||
@Override
|
||||
public void postUpdate(final Object entity) {
|
||||
setEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
private static class PreRemoveEntityListener extends AbstractEntityListener {
|
||||
@Override
|
||||
public void preRemove(final Object entity) {
|
||||
setEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
private static class PostRemoveEntityListener extends AbstractEntityListener {
|
||||
@Override
|
||||
public void postRemove(final Object entity) {
|
||||
setEntity(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
pom.xml
39
pom.xml
@@ -100,7 +100,6 @@
|
||||
<org.powermock.version>1.5.4</org.powermock.version>
|
||||
<pl.pragmatists.version>1.0.2</pl.pragmatists.version>
|
||||
<json-path.version>0.9.1</json-path.version>
|
||||
<aspectj.version>1.8.5</aspectj.version>
|
||||
<guava.version>19.0</guava.version>
|
||||
<mariadb-java-client.version>1.4.3</mariadb-java-client.version>
|
||||
<embedded-mongo.version>1.50.2</embedded-mongo.version>
|
||||
@@ -124,33 +123,13 @@
|
||||
<!-- Sonar - START-->
|
||||
<sonar.host.url>https://sonar.eu-gb.mybluemix.net</sonar.host.url>
|
||||
<sonar.github.repository>eclipse/hawkbit</sonar.github.repository>
|
||||
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
|
||||
<sonar.links.homepage>https://projects.eclipse.org/projects/iot.hawkbit</sonar.links.homepage>
|
||||
<sonar.links.ci>https://circleci.com/gh/eclipse/hawkbit</sonar.links.ci>
|
||||
<!-- Jacoco version to use -->
|
||||
<jacoco.version>0.7.7.201606060606</jacoco.version>
|
||||
<!-- The Sonar Jacoco Listener for JUnit to extract coverage details
|
||||
per test -->
|
||||
<sonar-jacoco-listeners.version>1.4</sonar-jacoco-listeners.version>
|
||||
<!-- Don't let Sonar execute tests. We will ask it to Maven -->
|
||||
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
|
||||
<!-- The system property jacoco.outputDir needs to be override on the
|
||||
command line with an absolute path if you want to merge results from all
|
||||
modules. Example in a Jenkisn build where ${WORKSPACE} is defined and your
|
||||
project in the root directory of the workspace : mvn clean install -Prun-its,coverage
|
||||
-Djacoco.outputDir=${WORKSPACE}/target Note that unfortunately using the
|
||||
following does not work because of http://jira.codehaus.org/browse/SONAR-3427:
|
||||
<jacoco.outputDir>${session.executionRootDirectory}/target/</jacoco.outputDir> -->
|
||||
<jacoco.outputDir>${project.basedir}/../target/</jacoco.outputDir>
|
||||
<!-- Jacoco output file for UTs -->
|
||||
<jacoco.out.ut.file>jacoco-ut.exec</jacoco.out.ut.file>
|
||||
<!-- Tells Sonar where the Jacoco coverage result file is located for
|
||||
Unit Tests -->
|
||||
<sonar.jacoco.reportPath>${jacoco.outputDir}/${jacoco.out.ut.file}</sonar.jacoco.reportPath>
|
||||
<!-- Jacoco output file for ITs -->
|
||||
<jacoco.out.it.file>jacoco-it.exec</jacoco.out.it.file>
|
||||
<!-- Tells Sonar where the Jacoco coverage result file is located for
|
||||
Integration Tests -->
|
||||
<sonar.jacoco.itReportPath>${jacoco.outputDir}/${jacoco.out.it.file}</sonar.jacoco.itReportPath>
|
||||
<!-- Sonar - END-->
|
||||
</properties>
|
||||
@@ -295,7 +274,6 @@
|
||||
<forkCount>1</forkCount>
|
||||
<argLine>
|
||||
${jacoco.agent.ut.arg}
|
||||
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
|
||||
</argLine>
|
||||
<properties>
|
||||
<property>
|
||||
@@ -312,13 +290,6 @@
|
||||
<exclude>**/Abstract*.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@@ -326,8 +297,7 @@
|
||||
<configuration>
|
||||
<reuseForks>true</reuseForks>
|
||||
<forkCount>3</forkCount>
|
||||
<argLine>-Xmx1024m ${jacoco.agent.ut.arg}
|
||||
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"</argLine>
|
||||
<argLine>-Xmx1024m ${jacoco.agent.ut.arg}</argLine>
|
||||
<properties>
|
||||
<property>
|
||||
<name>listener</name>
|
||||
@@ -335,13 +305,6 @@
|
||||
</property>
|
||||
</properties>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>integration-test</id>
|
||||
|
||||
Reference in New Issue
Block a user