Skip to content

Commit

Permalink
chore: Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
maikelarabori committed Nov 16, 2023
2 parents a74b2be + 6f139a6 commit 09292ad
Show file tree
Hide file tree
Showing 271 changed files with 1,813 additions and 1,420 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/run-api-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
branches:
- master
pull_request:
types: [ opened, labeled, synchronize ]
concurrency:
group: ${{ github.workflow}}-${{ github.ref }}
cancel-in-progress: true
Expand All @@ -20,7 +19,6 @@ jobs:
CORE_IMAGE_NAME: "dhis2/core-pr:${{ github.event_name == 'pull_request' && github.event.number || 'local' }}"

runs-on: ubuntu-latest
if: "!contains(github.event.pull_request.labels.*.name, 'skip-api-tests')"
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
Expand Down
Empty file modified dhis-2/build.sh
100755 → 100644
Empty file.
4 changes: 4 additions & 0 deletions dhis-2/dhis-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
<groupId>org.hisp.dhis.rules</groupId>
<artifactId>rule-engine</artifactId>
</dependency>
<dependency>
<groupId>org.hisp.dhis</groupId>
<artifactId>json-tree</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
*/
package org.hisp.dhis.dbms;

import java.io.Serializable;
import java.util.List;

/**
Expand All @@ -47,10 +46,4 @@ public interface DbmsManager {
boolean tableExists(String tableName);

List<List<Object>> getTableContent(String table);

void evictObject(Object object);

boolean contains(Object object);

Serializable getIdentifier(Object object);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public interface ReservedValueStore extends GenericStore<ReservedValue> {
List<ReservedValue> getAvailableValues(
ReservedValue reservedValue, List<String> values, String ownerObject);

List<ReservedValue> reserveValuesJpa(ReservedValue reservedValue, List<String> values);

int getNumberOfUsedValues(ReservedValue reservedValue);

boolean useReservedValue(String ownerUID, String value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import org.hisp.dhis.feedback.ConflictException;
import org.hisp.dhis.jsontree.JsonObject;
import org.hisp.dhis.schema.Property;
import org.springframework.util.MimeType;

Expand Down Expand Up @@ -160,6 +162,13 @@ String create(JobConfiguration config, MimeType contentType, InputStream content
*/
List<JobConfiguration> getStaleConfigurations(int staleForSeconds);

/**
* @param params query parameters (criteria) to find
* @return all job configurations that match the query parameters
*/
@Nonnull
List<JsonObject> findJobRunErrors(@Nonnull JobRunErrorsParams params);

/**
* Get a map of parameter classes with appropriate properties This can be used for a frontend app
* or for other appropriate applications which needs information about the jobs in the system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ public interface JobConfigurationStore extends GenericDimensionalObjectStore<Job
*/
Stream<JobConfiguration> getDueJobConfigurations(boolean includeWaiting);

/**
* @param params query parameters (criteria) to find
* @return all job configurations that match the query parameters
*/
@Nonnull
Stream<String> findJobRunErrors(@Nonnull JobRunErrorsParams params);

/**
* @return A list of all job types that are currently in {@link JobStatus#RUNNING} state.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,18 @@ default boolean isSkipCurrentStage() {
Error reporting API:
*/

default void addError(ErrorCode code, String uid, String type, Integer index, String... args) {
addError(code, uid, type, index, List.of(args));
default void addError(
@Nonnull ErrorCode code, @CheckForNull String uid, @Nonnull String type, String... args) {
addError(code, uid, type, List.of(args));
}

default void addError(ErrorCode code, String uid, String type, Integer index, List<String> args) {
// default implementation is a NOOP, we don't remember or handle the error
default void addError(
@Nonnull ErrorCode code,
@CheckForNull String uid,
@Nonnull String type,
@Nonnull List<String> args) {
// is overridden by a tracker that collects errors
// default is to not collect errors
}

/*
Expand Down Expand Up @@ -590,10 +596,13 @@ public Progress(
}

public void addError(Error error) {
errors
.computeIfAbsent(error.getId(), key -> new ConcurrentHashMap<>())
.computeIfAbsent(error.getCode(), key2 -> new ConcurrentLinkedQueue<>())
.add(error);
Queue<Error> sameObjectAndCode =
errors
.computeIfAbsent(error.getId(), key -> new ConcurrentHashMap<>())
.computeIfAbsent(error.getCode(), key2 -> new ConcurrentLinkedQueue<>());
if (sameObjectAndCode.stream().noneMatch(e -> e.args.equals(error.args))) {
sameObjectAndCode.add(error);
}
}

public boolean hasErrors() {
Expand All @@ -619,13 +628,6 @@ final class Error {
/** The type of the object identified by #id that has the error */
@Nonnull @JsonProperty private final String type;

/**
* The row index in the payload of the import. This is the index in the list of objects of a
* single type. This means the same index occurs for each object type. For some imports this
* information is not available.
*/
@CheckForNull @JsonProperty private final Integer index;

/** The arguments used in the {@link #code}'s {@link ErrorCode#getMessage()} template */
@Nonnull @JsonProperty private final List<String> args;

Expand All @@ -642,12 +644,10 @@ public Error(
@Nonnull @JsonProperty("code") ErrorCode code,
@Nonnull @JsonProperty("id") String id,
@Nonnull @JsonProperty("type") String type,
@CheckForNull @JsonProperty("index") Integer index,
@Nonnull @JsonProperty("args") List<String> args) {
this.code = code;
this.id = id;
this.type = type;
this.index = index;
this.args = args;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2004-2023, 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.scheduling;

import java.util.Date;
import java.util.List;
import javax.annotation.CheckForNull;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hisp.dhis.common.OpenApi;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.feedback.ErrorCode;
import org.hisp.dhis.user.User;

/**
* Query params when searching for {@link JobConfiguration}s with errors.
*
* <p>A match has to satisfy all filters (AND logic) but only one of the given codes or object
* {@link UID} (OR logic).
*
* <p>If any of the criteria is not defined it has no filter effect.
*
* @author Jan Bernitt
*/
@Data
@Accessors(chain = true)
public class JobRunErrorsParams {

@OpenApi.Ignore @CheckForNull private UID job;

/** The user that ran the job */
@OpenApi.Property({UID.class, User.class})
@CheckForNull
private UID user;

/** The earliest date the job ran that should be included */
@CheckForNull private Date from;

/** The latest date the job ran that should be included */
@CheckForNull private Date to;

/** The codes to select, any match combined */
@CheckForNull private List<ErrorCode> code;

/** The object with errors to select, any match combined */
@CheckForNull private List<UID> object;

/** The {@link JobType} with errors to select, any match combined */
@CheckForNull private List<JobType> type;
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public String getCurrentUsername() {
return CurrentUserUtil.getCurrentUsername();
}

@Transactional(readOnly = true)
public User getCurrentUser() {
String username = CurrentUserUtil.getCurrentUsername();

Expand Down
4 changes: 2 additions & 2 deletions dhis-2/dhis-services/dhis-service-administration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@

import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import lombok.RequiredArgsConstructor;
import org.hibernate.SessionFactory;
import org.hisp.dhis.dataintegrity.DataIntegrityCheck;
import org.hisp.dhis.dataintegrity.DataIntegrityDetails;
import org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue;
Expand All @@ -50,13 +51,13 @@
@Repository
@RequiredArgsConstructor
public class HibernateDataIntegrityStore implements DataIntegrityStore {
private final SessionFactory sessionFactory;
@PersistenceContext private final EntityManager entityManager;

@Override
@Transactional(readOnly = true)
public DataIntegritySummary querySummary(DataIntegrityCheck check, String sql) {
Date startTime = new Date();
Object summary = sessionFactory.getCurrentSession().createNativeQuery(sql).getSingleResult();
Object summary = entityManager.createNativeQuery(sql).getSingleResult();
return new DataIntegritySummary(
check, startTime, new Date(), null, parseCount(summary), parsePercentage(summary));
}
Expand All @@ -66,7 +67,7 @@ public DataIntegritySummary querySummary(DataIntegrityCheck check, String sql) {
public DataIntegrityDetails queryDetails(DataIntegrityCheck check, String sql) {
Date startTime = new Date();
@SuppressWarnings("unchecked")
List<Object[]> rows = sessionFactory.getCurrentSession().createNativeQuery(sql).getResultList();
List<Object[]> rows = entityManager.createNativeQuery(sql).getResultList();
return new DataIntegrityDetails(
check,
startTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

import static org.hisp.dhis.common.IdentifiableObjectUtils.getIdentifiers;

import javax.persistence.EntityManager;
import lombok.RequiredArgsConstructor;
import org.hibernate.SessionFactory;
import org.hisp.dhis.common.IdentifiableObjectUtils;
import org.hisp.dhis.dataapproval.DataApprovalAuditService;
import org.hisp.dhis.dataset.DataSetService;
Expand All @@ -55,7 +55,7 @@
@Transactional
@RequiredArgsConstructor
public class DataOrgUnitMergeHandler {
private final SessionFactory sessionFactory;
private final EntityManager entityManager;

private final NamedParameterJdbcTemplate jdbcTemplate;

Expand Down Expand Up @@ -201,11 +201,10 @@ public void mergeInterpretations(OrgUnitMergeRequest request) {
}

private void migrate(String hql, OrgUnitMergeRequest request) {
sessionFactory
.getCurrentSession()
entityManager
.createQuery(hql)
.setParameter("target", request.getTarget())
.setParameterList("sources", IdentifiableObjectUtils.getIdentifiers(request.getSources()))
.setParameter("sources", IdentifiableObjectUtils.getIdentifiers(request.getSources()))
.executeUpdate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
*/
package org.hisp.dhis.merge.orgunit.handler;

import javax.persistence.EntityManager;
import lombok.RequiredArgsConstructor;
import org.hibernate.SessionFactory;
import org.hisp.dhis.common.IdentifiableObjectUtils;
import org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest;
import org.springframework.stereotype.Service;
Expand All @@ -42,7 +42,7 @@
@Service
@RequiredArgsConstructor
public class TrackerOrgUnitMergeHandler {
private final SessionFactory sessionFactory;
private final EntityManager entityManager;

@Transactional
public void mergeProgramMessages(OrgUnitMergeRequest request) {
Expand Down Expand Up @@ -90,11 +90,10 @@ public void mergeTrackedEntities(OrgUnitMergeRequest request) {
}

private void migrate(String hql, OrgUnitMergeRequest request) {
sessionFactory
.getCurrentSession()
entityManager
.createQuery(hql)
.setParameter("target", request.getTarget())
.setParameterList("sources", IdentifiableObjectUtils.getIdentifiers(request.getSources()))
.setParameter("sources", IdentifiableObjectUtils.getIdentifiers(request.getSources()))
.executeUpdate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
*/
package org.hisp.dhis.split.orgunit.handler;

import javax.persistence.EntityManager;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.SessionFactory;
import org.hisp.dhis.split.orgunit.OrgUnitSplitRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -46,7 +46,7 @@ public class DataOrgUnitSplitHandler {

private static final String PARAM_SOURCE = "source";

private final SessionFactory sessionFactory;
private final EntityManager entityManager;

@Transactional
public void splitData(OrgUnitSplitRequest request) {
Expand Down Expand Up @@ -74,8 +74,7 @@ private void migrate(OrgUnitSplitRequest request, String entity, String property

log.debug("Update data HQL: '{}'", hql);

sessionFactory
.getCurrentSession()
entityManager
.createQuery(hql)
.setParameter("source", request.getSource())
.setParameter("target", request.getPrimaryTarget())
Expand Down
Loading

0 comments on commit 09292ad

Please sign in to comment.