Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Mar 12, 2022
2 parents 10a3cec + 32dc1f7 commit 1852905
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 240 deletions.
169 changes: 62 additions & 107 deletions .editorconfig

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
/*
* Copyright (c) 2010-2020 Evolveum and contributors
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.schema.util;

import java.util.*;
import java.util.Objects;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType;
import com.evolveum.prism.xml.ns._public.query_3.PagingType;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.prism.ItemProcessing;
Expand All @@ -25,7 +21,9 @@
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.*;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.expression.ExpressionProfile;
Expand All @@ -34,7 +32,9 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType;
import com.evolveum.midpoint.xml.ns._public.common.api_types_3.PropertyReferenceListType;
import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.query_3.PagingType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;

Expand Down Expand Up @@ -446,9 +446,6 @@ public static void mergePaging(PagingType existPaging, PagingType newPaging) {
if (existPaging.getMaxSize() == null) {
existPaging.setMaxSize(newPaging.getMaxSize());
}
if (existPaging.getGroupBy() == null) {
existPaging.setGroupBy(newPaging.getGroupBy());
}
if (existPaging.getOffset() == null) {
existPaging.setOffset(newPaging.getOffset());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,35 +108,35 @@ private <DP extends GuiObjectDetailsPageType> DP mergeDetailsPages(DP defaultPag
return mergedDetailsPage;
}

private SummaryPanelSpecificationType mergeSummaryPanels(SummaryPanelSpecificationType defaultSummaryPanelConfiguration, SummaryPanelSpecificationType compiledSummaryPanelConfiguration) {
if (compiledSummaryPanelConfiguration == null) {
return defaultSummaryPanelConfiguration;
private SummaryPanelSpecificationType mergeSummaryPanels(SummaryPanelSpecificationType defaultSummary, SummaryPanelSpecificationType compiledSummary) {
if (compiledSummary == null) {
return defaultSummary;
}

if (defaultSummaryPanelConfiguration == null) {
return compiledSummaryPanelConfiguration;
if (defaultSummary == null) {
return compiledSummary;
}

SummaryPanelSpecificationType mergedSummaryPanel = defaultSummaryPanelConfiguration.cloneWithoutId();
GuiFlexibleLabelType mergedIdentifier = mergeSummaryPanelFlexibleLabel(defaultSummaryPanelConfiguration.getIdentifier(), compiledSummaryPanelConfiguration.getIdentifier());
mergedSummaryPanel.setIdentifier(mergedIdentifier);
SummaryPanelSpecificationType mergedSummary = defaultSummary.cloneWithoutId();
GuiFlexibleLabelType mergedIdentifier = mergeSummaryPanelFlexibleLabel(defaultSummary.getIdentifier(), compiledSummary.getIdentifier());
mergedSummary.setIdentifier(mergedIdentifier);

GuiFlexibleLabelType mergedDisplayName = mergeSummaryPanelFlexibleLabel(defaultSummaryPanelConfiguration.getDisplayName(), compiledSummaryPanelConfiguration.getDisplayName());
mergedSummaryPanel.setIdentifier(mergedDisplayName);
GuiFlexibleLabelType mergedDisplayName = mergeSummaryPanelFlexibleLabel(defaultSummary.getDisplayName(), compiledSummary.getDisplayName());
mergedSummary.setDisplayName(mergedDisplayName);

GuiFlexibleLabelType mergedOrganization = mergeSummaryPanelFlexibleLabel(defaultSummaryPanelConfiguration.getOrganization(), compiledSummaryPanelConfiguration.getOrganization());
mergedSummaryPanel.setIdentifier(mergedOrganization);
GuiFlexibleLabelType mergedOrganization = mergeSummaryPanelFlexibleLabel(defaultSummary.getOrganization(), compiledSummary.getOrganization());
mergedSummary.setOrganization(mergedOrganization);

GuiFlexibleLabelType mergedTitle1 = mergeSummaryPanelFlexibleLabel(defaultSummaryPanelConfiguration.getTitle1(), compiledSummaryPanelConfiguration.getTitle1());
mergedSummaryPanel.setIdentifier(mergedTitle1);
GuiFlexibleLabelType mergedTitle1 = mergeSummaryPanelFlexibleLabel(defaultSummary.getTitle1(), compiledSummary.getTitle1());
mergedSummary.setTitle1(mergedTitle1);

GuiFlexibleLabelType mergedTitle2 = mergeSummaryPanelFlexibleLabel(defaultSummaryPanelConfiguration.getTitle2(), compiledSummaryPanelConfiguration.getTitle2());
mergedSummaryPanel.setIdentifier(mergedTitle2);
GuiFlexibleLabelType mergedTitle2 = mergeSummaryPanelFlexibleLabel(defaultSummary.getTitle2(), compiledSummary.getTitle2());
mergedSummary.setTitle2(mergedTitle2);

GuiFlexibleLabelType mergedTitle3 = mergeSummaryPanelFlexibleLabel(defaultSummaryPanelConfiguration.getTitle3(), compiledSummaryPanelConfiguration.getTitle3());
mergedSummaryPanel.setIdentifier(mergedTitle3);
GuiFlexibleLabelType mergedTitle3 = mergeSummaryPanelFlexibleLabel(defaultSummary.getTitle3(), compiledSummary.getTitle3());
mergedSummary.setTitle3(mergedTitle3);

return mergedSummaryPanel;
return mergedSummary;
}

private GuiFlexibleLabelType mergeSummaryPanelFlexibleLabel(GuiFlexibleLabelType defaultSummaryPanelIdentifier, GuiFlexibleLabelType compiledSummaryPanelIdentifier) {
Expand Down Expand Up @@ -413,5 +413,4 @@ private IconType mergeIcon(IconType currentIcon, IconType superIcon) {
private boolean pathsMatch(ItemPathType supperPath, ItemPathType currentPath) {
return supperPath != null && currentPath != null && supperPath.equivalent(currentPath);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand Down Expand Up @@ -977,7 +977,7 @@ public static boolean isCustomPagingOkWithPagedSeqIteration(ObjectQuery query) {
return true;
}
ObjectPaging paging = query.getPaging();
return !paging.hasOrdering() && !paging.hasGrouping() && paging.getOffset() == null;
return !paging.hasOrdering() && paging.getOffset() == null;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand Down Expand Up @@ -352,12 +352,6 @@ private void updatePagingAndSorting(InterpretationContext context, ObjectPaging
addOrdering(context, ordering);
}
}

if (paging.hasGrouping()) {
for (ObjectGrouping grouping : paging.getGroupingInstructions()) {
addGrouping(context, grouping);
}
}
}

private void addOrdering(InterpretationContext context, ObjectOrdering ordering) throws QueryException {
Expand Down Expand Up @@ -410,45 +404,6 @@ private void addOrdering(InterpretationContext context, ObjectOrdering ordering)

}

private void addGrouping(InterpretationContext context, ObjectGrouping grouping) throws QueryException {

ItemPath groupByPath = grouping.getGroupBy();

// TODO if we'd like to have group-by extension properties, we'd need to provide itemDefinition for them
ProperDataSearchResult<?> result = context.getItemPathResolver().findProperDataDefinition(
context.getRootEntityDefinition(), groupByPath, null, JpaDataNodeDefinition.class, context.getPrismContext());
if (result == null) {
LOGGER.error("Unknown path '" + groupByPath + "', couldn't find definition for it, "
+ "list will not be grouped by it.");
return;
}
JpaDataNodeDefinition targetDefinition = result.getLinkDefinition().getTargetDefinition();
if (targetDefinition instanceof JpaAnyContainerDefinition) {
throw new QueryException("Grouping based on extension item or attribute is not supported yet: " + groupByPath);
} else if (targetDefinition instanceof JpaReferenceDefinition) {
throw new QueryException("Grouping based on reference is not supported: " + groupByPath);
} else if (result.getLinkDefinition().isMultivalued()) {
throw new QueryException("Grouping based on multi-valued item is not supported: " + groupByPath);
} else if (targetDefinition instanceof JpaEntityDefinition) {
throw new QueryException("Grouping based on entity is not supported: " + groupByPath);
} else if (!(targetDefinition instanceof JpaPropertyDefinition)) {
throw new IllegalStateException("Unknown item definition type: " + result.getClass());
}

JpaEntityDefinition baseEntityDefinition = result.getEntityDefinition();
JpaPropertyDefinition groupByDefinition = (JpaPropertyDefinition) targetDefinition;
String hqlPropertyPath = context.getItemPathResolver()
.resolveItemPath(groupByPath, null, context.getPrimaryEntityAlias(), baseEntityDefinition, true)
.getHqlPath();
if (RPolyString.class.equals(groupByDefinition.getJpaClass())) {
hqlPropertyPath += ".orig";
}

RootHibernateQuery hibernateQuery = context.getHibernateQuery();

hibernateQuery.addGrouping(hqlPropertyPath);
}

public <T> Matcher<T> findMatcher(T value) {
//noinspection unchecked
return findMatcher(value != null ? (Class<T>) value.getClass() : null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/*
* Copyright (c) 2010-2015 Evolveum and contributors
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.repo.sql.query.hqm;

import java.util.ArrayList;
Expand Down Expand Up @@ -47,8 +46,6 @@ public abstract class HibernateQuery {

private final List<Ordering> orderingList = new ArrayList<>();

private final List<Grouping> groupingList = new ArrayList<>();

public HibernateQuery(@NotNull JpaEntityDefinition primaryEntityDef) {
primaryEntity = createItemSpecification(primaryEntityDef);
}
Expand Down Expand Up @@ -76,19 +73,6 @@ public OrderDirection getDirection() {
}
}

public static class Grouping {
@NotNull private final String byProperty;

Grouping(@NotNull String byProperty) {
this.byProperty = byProperty;
}

@NotNull
public String getByProperty() {
return byProperty;
}
}

public List<ProjectionElement> getProjectionElements() {
return projectionElements;
}
Expand Down Expand Up @@ -165,21 +149,6 @@ public String getAsHqlText(int indent, boolean distinct) {
}
}

if (!groupingList.isEmpty()) {
sb.append("\n");
indent(sb, indent);
sb.append("group by ");
boolean first = true;
for (Grouping grouping : groupingList) {
if (first) {
first = false;
} else {
sb.append(", ");
}
sb.append(grouping.byProperty);
}
}

return sb.toString();
}

Expand All @@ -198,7 +167,7 @@ public String createAlias(JpaEntityDefinition def) {
return createAlias(def.getJpaClassName(), true);
}

public String createAlias(JpaLinkDefinition linkDefinition) {
public String createAlias(JpaLinkDefinition<?> linkDefinition) {
Objects.requireNonNull(linkDefinition.getJpaName(), "Got unnamed transition");
return createAlias(linkDefinition.getJpaName(), false);
}
Expand Down Expand Up @@ -251,14 +220,4 @@ public void addOrdering(String propertyPath, OrderDirection direction) {
public List<Ordering> getOrderingList() {
return orderingList;
}

public void addGrouping(String propertyPath) {
groupingList.add(new Grouping(propertyPath));
}

public List<Grouping> getGroupingList() {
return groupingList;
}

public abstract RootHibernateQuery getRootQuery();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2020 Evolveum and contributors
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand Down Expand Up @@ -109,11 +109,6 @@ public Query getAsHqlQuery(Session session) {
return query;
}

@Override
public RootHibernateQuery getRootQuery() {
return this;
}

public void setMaxResults(Integer size) {
this.maxResults = size;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.core.Appender;
import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.encoder.Encoder;

import com.evolveum.midpoint.ninja.impl.LogTarget;
import com.evolveum.midpoint.ninja.impl.NinjaContext;
import com.evolveum.midpoint.ninja.opts.BaseOptions;

import org.slf4j.LoggerFactory;

/**
Expand All @@ -27,6 +30,10 @@ public class Log {

private static final String LOGGER_SYS_ERR = "SYSERR";

private static final String APPENDER_SYS_OUT = "STDOUT";

private static final String APPENDER_SYS_ERR = "STDERR";

private LogTarget target;
private NinjaContext context;

Expand All @@ -46,6 +53,7 @@ private void init() {
opts = NinjaUtils.getOptions(context.getJc(), BaseOptions.class);

LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
lc.reset();
PatternLayoutEncoder ple = new PatternLayoutEncoder();

if (opts.isVerbose()) {
Expand All @@ -57,14 +65,14 @@ private void init() {
ple.setContext(lc);
ple.start();

ConsoleAppender out = setupAppender("STDOUT","System.out", lc, setupEncoder(lc));
ConsoleAppender err = setupAppender("STDERR","System.err", lc, setupEncoder(lc));
ConsoleAppender err = setupAppender(APPENDER_SYS_ERR, "System.err", lc, setupEncoder(lc));

Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
if (LogTarget.SYSTEM_OUT.equals(target)) {
root.addAppender(out);
ConsoleAppender out = setupAppender(APPENDER_SYS_OUT, "System.out", lc, setupEncoder(lc));
addAppender(root, out);
} else {
root.addAppender(err);
addAppender(root, err);
}

root.setLevel(Level.OFF);
Expand All @@ -73,7 +81,15 @@ private void init() {

error = setupLogger(LOGGER_SYS_ERR, opts);
error.setAdditive(false);
error.addAppender(err);
addAppender(error, err);
}

private void addAppender(Logger logger, Appender appender) {
if (logger == null || logger.getAppender(appender.getName()) != null) {
return;
}

logger.addAppender(appender);
}

private Logger setupLogger(String name, BaseOptions opts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.tools.testng.UnusedTestElement;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
Expand All @@ -24,7 +23,6 @@
/**
* Created by Viliam Repan (lazyman).
*/
@UnusedTestElement("2 of 5 fails")
public class ImportRepositoryTest extends BaseTest {

@BeforeMethod
Expand Down
1 change: 1 addition & 0 deletions tools/ninja/testng-unit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<class name="com.evolveum.midpoint.ninja.ExportRepositoryTest"/>
<class name="com.evolveum.midpoint.ninja.HelpTest"/>
<class name="com.evolveum.midpoint.ninja.ListKeysTest"/>
<class name="com.evolveum.midpoint.ninja.ImportRepositoryTest"/>
</classes>
</test>
</suite>

0 comments on commit 1852905

Please sign in to comment.