-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Move Changelog service to tracker module [DHIS2-17835] (#18425)
* chore: Move Changelog service to tracker module [DHIS2-17835] * chore: Fix sonar issues [DHIS2-17835] * chore: Fix sonar issues [DHIS2-17835] * chore: Fix sonar issues [DHIS2-17835] * chore: Fix h2 jsonB test [DHIS2-17835] * chore: Rename package [DHIS2-17835]
- Loading branch information
Showing
24 changed files
with
352 additions
and
161 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/ApiTrackedEntityAuditService.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2004-2022, University of Oslo | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* Neither the name of the HISP project nor the names of its contributors may | ||
* be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package org.hisp.dhis.trackedentity; | ||
|
||
import org.hisp.dhis.changelog.ChangeLogType; | ||
|
||
/** | ||
* @author Abyot Asalefew Gizaw [email protected] | ||
*/ | ||
public interface ApiTrackedEntityAuditService { | ||
|
||
String ID = ApiTrackedEntityAuditService.class.getName(); | ||
|
||
void addTrackedEntityAudit( | ||
TrackedEntity trackedEntity, String username, ChangeLogType changeLogType); | ||
} |
42 changes: 42 additions & 0 deletions
42
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/ApiTrackedEntityAuditStore.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2004-2022, University of Oslo | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* Neither the name of the HISP project nor the names of its contributors may | ||
* be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package org.hisp.dhis.trackedentity; | ||
|
||
/** | ||
* @author Abyot Asalefew Gizaw [email protected] | ||
*/ | ||
public interface ApiTrackedEntityAuditStore { | ||
String ID = ApiTrackedEntityAuditStore.class.getName(); | ||
|
||
/** | ||
* Adds the given tracked entity audit. | ||
* | ||
* @param trackedEntityAudit the {@link TrackedEntityAudit} to add. | ||
*/ | ||
void addTrackedEntityAudit(TrackedEntityAudit trackedEntityAudit); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ | |
* @author Abyot Asalefew Gizaw [email protected] | ||
*/ | ||
@JacksonXmlRootElement(localName = "trackedEntityInstanceAudit", namespace = DxfNamespaces.DXF_2_0) | ||
public class TrackedEntityChangeLog implements Serializable { | ||
public class TrackedEntityAudit implements Serializable { | ||
private static final long serialVersionUID = 4260110537887403524L; | ||
|
||
private long id; | ||
|
@@ -61,16 +61,16 @@ public class TrackedEntityChangeLog implements Serializable { | |
// Constructors | ||
// ------------------------------------------------------------------------- | ||
|
||
public TrackedEntityChangeLog() {} | ||
public TrackedEntityAudit() {} | ||
|
||
public TrackedEntityChangeLog(String trackedEntity, String accessedBy, ChangeLogType auditType) { | ||
public TrackedEntityAudit(String trackedEntity, String accessedBy, ChangeLogType auditType) { | ||
this.trackedEntity = trackedEntity; | ||
this.accessedBy = accessedBy; | ||
this.created = new Date(); | ||
this.auditType = auditType; | ||
} | ||
|
||
public TrackedEntityChangeLog( | ||
public TrackedEntityAudit( | ||
String trackedEntity, | ||
String comment, | ||
Date created, | ||
|
@@ -96,7 +96,7 @@ public boolean equals(Object obj) { | |
return false; | ||
} | ||
|
||
final TrackedEntityChangeLog other = (TrackedEntityChangeLog) obj; | ||
final TrackedEntityAudit other = (TrackedEntityAudit) obj; | ||
|
||
return Objects.equals(this.trackedEntity, other.trackedEntity) | ||
&& Objects.equals(this.comment, other.comment) | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
58 changes: 58 additions & 0 deletions
58
...e-core/src/main/java/org/hisp/dhis/trackedentity/DefaultApiTrackedEntityAuditService.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2004-2022, University of Oslo | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* Neither the name of the HISP project nor the names of its contributors may | ||
* be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package org.hisp.dhis.trackedentity; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.hisp.dhis.changelog.ChangeLogType; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
/** | ||
* @author Abyot Asalefew Gizaw [email protected] | ||
*/ | ||
@RequiredArgsConstructor | ||
@Service("org.hisp.dhis.trackedentity.ApiTrackedEntityAuditService") | ||
public class DefaultApiTrackedEntityAuditService implements ApiTrackedEntityAuditService { | ||
private final ApiTrackedEntityAuditStore apiTrackedEntityAuditStore; | ||
|
||
@Override | ||
@Async | ||
@Transactional | ||
public void addTrackedEntityAudit( | ||
TrackedEntity trackedEntity, String username, ChangeLogType changeLogType) { | ||
if (username != null | ||
&& trackedEntity != null | ||
&& trackedEntity.getTrackedEntityType() != null | ||
&& trackedEntity.getTrackedEntityType().isAllowAuditLog()) { | ||
TrackedEntityAudit trackedEntityAudit = | ||
new TrackedEntityAudit(trackedEntity.getUid(), username, changeLogType); | ||
apiTrackedEntityAuditStore.addTrackedEntityAudit(trackedEntityAudit); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
.../main/java/org/hisp/dhis/trackedentity/hibernate/HibernateApiTrackedEntityAuditStore.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2004-2022, University of Oslo | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* Neither the name of the HISP project nor the names of its contributors may | ||
* be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package org.hisp.dhis.trackedentity.hibernate; | ||
|
||
import javax.persistence.EntityManager; | ||
import org.hisp.dhis.hibernate.HibernateGenericStore; | ||
import org.hisp.dhis.trackedentity.ApiTrackedEntityAuditStore; | ||
import org.hisp.dhis.trackedentity.TrackedEntityAudit; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.stereotype.Repository; | ||
|
||
/** | ||
* @author Abyot Asalefew Gizaw [email protected] | ||
*/ | ||
@Repository("org.hisp.dhis.trackedentity.ApiTrackedEntityAuditStore") | ||
public class HibernateApiTrackedEntityAuditStore extends HibernateGenericStore<TrackedEntityAudit> | ||
implements ApiTrackedEntityAuditStore { | ||
|
||
public HibernateApiTrackedEntityAuditStore( | ||
EntityManager entityManager, JdbcTemplate jdbcTemplate, ApplicationEventPublisher publisher) { | ||
super(entityManager, jdbcTemplate, publisher, TrackedEntityAudit.class, false); | ||
} | ||
|
||
// ------------------------------------------------------------------------- | ||
// ApiTrackedEntityAuditService implementation | ||
// ------------------------------------------------------------------------- | ||
|
||
@Override | ||
public void addTrackedEntityAudit(TrackedEntityAudit trackedEntityAudit) { | ||
getSession().save(trackedEntityAudit); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.