Skip to content

Commit

Permalink
Merge branch 'master' into duplicate-cocs-prevent-import
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-p-pickering authored Nov 27, 2024
2 parents 9229d5e + 4e3c716 commit ab040db
Show file tree
Hide file tree
Showing 263 changed files with 3,842 additions and 3,121 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run-api-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ jobs:
# build and publish multi-arch images using Jib. Image is used for api tests in
# this workflow and can be pulled from Dockerhub by devs to run locally, ...
mvn clean verify --threads 2C --batch-mode --no-transfer-progress \
-DskipTests --update-snapshots --file dhis-2/pom.xml \
-DskipTests -Dmdep.analyze.skip --update-snapshots --file dhis-2/pom.xml \
--projects dhis-web-server --also-make --activate-profiles jibBuild \
-Djib.to.image=$CORE_IMAGE_NAME -Djib.container.labels=DHIS2_BUILD_REVISION=${{github.event.pull_request.head.sha}},DHIS2_BUILD_BRANCH=${{github.head_ref}}
else
# only build image for running api tests in this workflow i.e. master, 2.39, ...
mvn clean verify --threads 2C --batch-mode --no-transfer-progress \
-DskipTests --update-snapshots --file dhis-2/pom.xml \
-DskipTests -Dmdep.analyze.skip --update-snapshots --file dhis-2/pom.xml \
--projects dhis-web-server --also-make --activate-profiles jibDockerBuild \
-Djib.to.image=$CORE_IMAGE_NAME
fi
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
- name: Run unit tests
run: mvn clean test --threads 2C --batch-mode --no-transfer-progress --update-snapshots --file ./dhis-2/pom.xml --activate-profiles unit-test
timeout-minutes: 30
- name: Run dependency analysis
run: mvn dependency:analyze --file ./dhis-2/pom.xml
timeout-minutes: 2
- name: Report coverage to codecov
uses: codecov/codecov-action@v3
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package org.hisp.dhis.category;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
Expand Down Expand Up @@ -195,6 +196,11 @@ public boolean hasOptionCombos() {
return optionCombos != null && !optionCombos.isEmpty();
}

@JsonIgnore
public List<Category> getDataDimensionCategories() {
return categories.stream().filter(Category::isDataDimension).toList();
}

// -------------------------------------------------------------------------
// Logic
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public static DimensionalObject linkAssociations(
EventAnalyticalObject eventAnalyticalObject,
DimensionalObject dimensionalObject,
Attribute parent) {
// Associating event repetitions.
List<EventRepetition> repetitions = eventAnalyticalObject.getEventRepetitions();

if (isNotEmpty(repetitions)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ <T extends IdentifiableObject> List<T> getByCode(
@CheckForNull
<T extends IdentifiableObject> T search(@Nonnull Class<T> type, @Nonnull String query);

@Nonnull
<T extends IdentifiableObject> List<T> filter(@Nonnull Class<T> type, @Nonnull String query);

@Nonnull
<T extends IdentifiableObject> List<T> getAll(@Nonnull Class<T> type);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ enum Status {
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@interface Shared {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ private static <T> Set<T> union(@Nonnull Set<T>... more) {
* @return a string, or null if no matches.
*/
public static String popStartsWith(Collection<String> collection, String prefix) {
if (collection == null || collection.isEmpty()) return null;
Iterator<String> iterator = collection.iterator();

while (iterator.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
import lombok.NoArgsConstructor;
import lombok.Setter;

/** Encapsulates metadata for an embedded and externally provided dashboard. */
/**
* Encapsulates metadata for an embedded and externally provided dashboard.
*
* @author Lars Helge Overland
*/
@Getter
@Setter
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
* Encapsulates embedded dashboard filter options.
*
* @author Lars Helge Overland
*/
@Getter
@Setter
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public enum FieldPreset {

FieldPreset(String name, List<String> fields) {
this.name = name;
this.fields = fields;
this.fields = List.copyOf(fields);
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -62,17 +61,4 @@ public static Set<User> getMentionedUsers(String text, UserService userService)
}
return users;
}

public static List<String> removeCustomFilters(List<String> filters) {
List<String> mentions = new ArrayList<String>();
ListIterator<String> filterIterator = filters.listIterator();
while (filterIterator.hasNext()) {
String[] filterSplit = filterIterator.next().split(":");
if (filterSplit[1].equals("in") && filterSplit[0].equals("mentions")) {
mentions.add(filterSplit[2]);
filterIterator.remove();
}
}
return mentions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.schema.annotation.PropertyRange;
import org.hisp.dhis.user.User;

Expand Down Expand Up @@ -192,12 +193,12 @@ public boolean isRead(User user) {
return false;
}

public boolean markRead(User user) {
for (UserMessage userMessage : userMessages) {
if (userMessage.getUser() != null && userMessage.getUser().equals(user)) {
boolean read = userMessage.isRead();
public boolean markRead(UID user) {
for (UserMessage msg : userMessages) {
if (msg.getUser() != null && msg.getUser().getUid().equals(user.getValue())) {
boolean read = msg.isRead();

userMessage.setRead(true);
msg.setRead(true);

return !read;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,6 @@ public interface OrganisationUnitService extends OrganisationUnitDataIntegrityPr
*/
List<OrganisationUnit> getOrganisationUnitsByUid(@Nonnull Collection<String> uids);

/**
* Returns a list of OrganisationUnits based on the given params.
*
* @param params the params.
* @return a list of OrganisationUnits.
*/
List<OrganisationUnit> getOrganisationUnitsByQuery(OrganisationUnitQueryParams params);

/**
* Returns an OrganisationUnit with a given name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package org.hisp.dhis.user;

import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -250,6 +251,14 @@ static UserDetails createUserDetails(

void setId(Long id);

default boolean canIssueUserRole(UserRole role, boolean canGrantOwnUserRole) {
if (role == null) return false;
if (isSuper()) return true;
if (hasAnyAuthorities(List.of(Authorities.ALL))) return true;
if (!canGrantOwnUserRole && getUserRoleIds().contains(role.getUid())) return false;
return getAllAuthorities().containsAll(role.getAuthorities());
}

default boolean isInUserHierarchy(String orgUnitPath) {
return isInUserHierarchy(orgUnitPath, getUserOrgUnitIds());
}
Expand Down
19 changes: 14 additions & 5 deletions dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.feedback.ConflictException;
import org.hisp.dhis.feedback.ErrorCode;
import org.hisp.dhis.feedback.ErrorReport;
import org.hisp.dhis.feedback.ForbiddenException;
Expand Down Expand Up @@ -235,6 +236,17 @@ static boolean hasTwoFactorSecretForApproval(User user) {
*/
List<User> getUsers(UserQueryParams params, @Nullable List<String> orders);

/**
* Returns a list of users based on the given query parameters. If the specified list of orders
* are empty, default order of last name and first name will be applied.
*
* @param params the user query parameters.
* @param orders the already validated order strings (e.g. email:asc).
* @return a List of users.
*/
List<UID> getUserIds(UserQueryParams params, @Nullable List<String> orders)
throws ConflictException;

/**
* Returns the number of users based on the given query parameters.
*
Expand Down Expand Up @@ -408,12 +420,9 @@ static boolean hasTwoFactorSecretForApproval(User user) {
int countDataSetUserRoles(DataSet dataSet);

/**
* Filters the given collection of user roles based on whether the current user is allowed to
* issue it.
*
* @param userRoles the collection of user roles.
* @return IDs of the roles the current user can issue
*/
void canIssueFilter(Collection<UserRole> userRoles);
List<UID> getRolesCurrentUserCanIssue();

/**
* Validate that the current user are allowed to create or modify properties of the given user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public interface UserStore extends IdentifiableObjectStore<User> {
*/
List<User> getUsers(UserQueryParams params, @Nullable List<String> orders);

List<UID> getUserIds(UserQueryParams params, @Nullable List<String> orders);

/**
* Returns the number of users based on the given query parameters.
*
Expand Down
2 changes: 1 addition & 1 deletion dhis-2/dhis-services/dhis-service-administration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>1.5.3</version>
<version>1.5.4</version>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,31 @@
*/
package org.hisp.dhis.analytics.config;

import org.hisp.dhis.analytics.AnalyticsTableHookService;
import org.hisp.dhis.analytics.AnalyticsTableManager;
import org.hisp.dhis.analytics.AnalyticsTableService;
import org.hisp.dhis.analytics.partition.PartitionManager;
import org.hisp.dhis.analytics.table.DefaultAnalyticsTableService;
import org.hisp.dhis.analytics.table.JdbcTrackedEntityEventsAnalyticsTableManager;
import org.hisp.dhis.analytics.table.setting.AnalyticsTableSettings;
import org.hisp.dhis.category.CategoryService;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.dataapproval.DataApprovalLevelService;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.db.sql.AnalyticsSqlBuilder;
import org.hisp.dhis.db.sql.AnalyticsSqlBuilderProvider;
import org.hisp.dhis.db.sql.SqlBuilder;
import org.hisp.dhis.db.sql.SqlBuilderProvider;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.PeriodDataProvider;
import org.hisp.dhis.resourcetable.ResourceTableService;
import org.hisp.dhis.setting.SystemSettingsProvider;
import org.hisp.dhis.system.database.DatabaseInfoProvider;
import org.hisp.dhis.trackedentity.TrackedEntityTypeService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

/**
* @author Luciano Fiandesio
Expand All @@ -50,6 +63,46 @@ public SqlBuilder sqlBuilder(SqlBuilderProvider provider) {
return provider.getSqlBuilder();
}

@Bean
public AnalyticsSqlBuilder analyticsSqlBuilder(AnalyticsSqlBuilderProvider provider) {
return provider.getAnalyticsSqlBuilder();
}

@Bean("org.hisp.dhis.analytics.TrackedEntityEventsAnalyticsTableManager")
public AnalyticsTableManager jdbcTrackedEntityEventsAnalyticsTableManager(
IdentifiableObjectManager idObjectManager,
OrganisationUnitService organisationUnitService,
CategoryService categoryService,
SystemSettingsProvider settingsProvider,
DataApprovalLevelService dataApprovalLevelService,
ResourceTableService resourceTableService,
AnalyticsTableHookService tableHookService,
PartitionManager partitionManager,
DatabaseInfoProvider databaseInfoProvider,
@Qualifier("analyticsJdbcTemplate") JdbcTemplate jdbcTemplate,
TrackedEntityTypeService trackedEntityTypeService,
AnalyticsTableSettings analyticsTableSettings,
PeriodDataProvider periodDataProvider,
SqlBuilder sqlBuilder,
AnalyticsSqlBuilder analyticsSqlBuilder) {
return new JdbcTrackedEntityEventsAnalyticsTableManager(
idObjectManager,
organisationUnitService,
categoryService,
settingsProvider,
dataApprovalLevelService,
resourceTableService,
tableHookService,
partitionManager,
databaseInfoProvider,
jdbcTemplate,
trackedEntityTypeService,
analyticsTableSettings,
periodDataProvider,
sqlBuilder,
analyticsSqlBuilder);
}

@Bean("org.hisp.dhis.analytics.TrackedEntityAnalyticsTableService")
public AnalyticsTableService trackedEntityAnalyticsTableManager(
@Qualifier("org.hisp.dhis.analytics.TrackedEntityAnalyticsTableManager")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
@Service("org.hisp.dhis.analytics.DataQueryService")
@RequiredArgsConstructor
public class DefaultDataQueryService implements DataQueryService {
private final DimensionalObjectProducer dimensionalObjectProducer;
private final DimensionalObjectProvider dimensionalObjectProducer;

private final IdentifiableObjectManager idObjectManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
*/
@Component
@RequiredArgsConstructor
public class DimensionalObjectProducer {
public class DimensionalObjectProvider {
private final IdentifiableObjectManager idObjectManager;

private final OrganisationUnitService organisationUnitService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.util.UUID;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.analytics.data.DimensionalObjectProducer;
import org.hisp.dhis.analytics.data.DimensionalObjectProvider;
import org.hisp.dhis.category.CategoryOptionCombo;
import org.hisp.dhis.common.BaseDimensionalObject;
import org.hisp.dhis.common.DisplayProperty;
Expand All @@ -60,7 +60,7 @@
@AllArgsConstructor
public class OutlierQueryParser {
private final IdentifiableObjectManager idObjectManager;
private final DimensionalObjectProducer dimensionalObjectProducer;
private final DimensionalObjectProvider dimensionalObjectProducer;
private final UserService userService;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import org.hisp.dhis.analytics.cache.OutliersCache;
import org.hisp.dhis.analytics.common.ColumnHeader;
import org.hisp.dhis.analytics.common.TableInfoReader;
import org.hisp.dhis.analytics.data.DimensionalObjectProducer;
import org.hisp.dhis.analytics.data.DimensionalObjectProvider;
import org.hisp.dhis.analytics.outlier.data.Outlier;
import org.hisp.dhis.analytics.outlier.data.OutlierRequest;
import org.hisp.dhis.category.CategoryOptionCombo;
Expand Down Expand Up @@ -104,7 +104,7 @@ public class AnalyticsOutlierService {

private final IdentifiableObjectManager idObjectManager;

private final DimensionalObjectProducer dimensionalObjectProducer;
private final DimensionalObjectProvider dimensionalObjectProducer;

/**
* Transform the incoming request into api response (json).
Expand Down
Loading

0 comments on commit ab040db

Please sign in to comment.