Skip to content

Commit

Permalink
Fixed ordering cert work items in GUI. Re-enabled isNull for multival…
Browse files Browse the repository at this point in the history
…ued references. Minor fix for isNull for references.
  • Loading branch information
mederly committed Apr 4, 2017
1 parent 21213db commit 655cae9
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 65 deletions.
Expand Up @@ -116,7 +116,7 @@ private CertWorkItemDtoProvider createProvider() {
provider.setQuery(createCaseQuery());
provider.setCampaignQuery(createCampaignQuery());
provider.setReviewerOid(getCurrentUserOid());
provider.setSort(AccessCertificationCaseType.F_CURRENT_REVIEW_DEADLINE.getLocalPart(), SortOrder.ASCENDING); // default sorting
provider.setSort(SearchingUtils.CURRENT_REVIEW_DEADLINE, SortOrder.ASCENDING); // default sorting
return provider;
}

Expand Down Expand Up @@ -259,8 +259,7 @@ public String getObject() {

column = new PropertyColumn<CertWorkItemDto, String>(
createStringResource("PageCertDecisions.table.requested"),
AccessCertificationCaseType.F_CURRENT_REVIEW_REQUESTED_TIMESTAMP.getLocalPart(),
CertWorkItemDto.F_REVIEW_REQUESTED) {
SearchingUtils.CURRENT_REVIEW_REQUESTED_TIMESTAMP, CertWorkItemDto.F_REVIEW_REQUESTED) {
@Override
public void populateItem(Item<ICellPopulator<CertWorkItemDto>> item, String componentId, IModel<CertWorkItemDto> rowModel) {
super.populateItem(item, componentId, rowModel);
Expand All @@ -275,7 +274,7 @@ public void populateItem(Item<ICellPopulator<CertWorkItemDto>> item, String comp
columns.add(column);

column = new PropertyColumn<CertWorkItemDto, String>(createStringResource("PageCertDecisions.table.deadline"),
AccessCertificationCaseType.F_CURRENT_REVIEW_DEADLINE.getLocalPart(), CertWorkItemDto.F_DEADLINE_AS_STRING) {
SearchingUtils.CURRENT_REVIEW_DEADLINE, CertWorkItemDto.F_DEADLINE_AS_STRING) {
@Override
public void populateItem(Item<ICellPopulator<CertWorkItemDto>> item, String componentId, final IModel<CertWorkItemDto> rowModel) {
super.populateItem(item, componentId, rowModel);
Expand Down
Expand Up @@ -11,10 +11,9 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.xml.namespace.QName;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand All @@ -26,12 +25,15 @@
*/
public class SearchingUtils {

@SuppressWarnings("unused")
private static final Trace LOGGER = TraceManager.getTrace(SearchingUtils.class);

public static final String TARGET_NAME = AccessCertificationCaseType.F_TARGET_REF.getLocalPart();
public static final String OBJECT_NAME = AccessCertificationCaseType.F_OBJECT_REF.getLocalPart();
public static final String TENANT_NAME = AccessCertificationCaseType.F_TENANT_REF.getLocalPart(); // seem to be unused now
public static final String ORG_NAME = AccessCertificationCaseType.F_ORG_REF.getLocalPart(); // seem to be unused now
public static final String CURRENT_REVIEW_DEADLINE = AccessCertificationCaseType.F_CURRENT_REVIEW_DEADLINE.getLocalPart();
public static final String CURRENT_REVIEW_REQUESTED_TIMESTAMP = AccessCertificationCaseType.F_CURRENT_REVIEW_REQUESTED_TIMESTAMP.getLocalPart();
public static final String CAMPAIGN_NAME = "campaignName";

@NotNull
Expand All @@ -41,24 +43,34 @@ public static List<ObjectOrdering> createObjectOrderings(SortParam<String> sortP
}
String propertyName = sortParam.getProperty();

ItemPath campaignPath = isWorkItem ? new ItemPath(T_PARENT, T_PARENT) : new ItemPath(T_PARENT);
ItemPath casePath = isWorkItem ? new ItemPath(T_PARENT) : ItemPath.EMPTY_PATH;
ItemPath campaignPath = casePath.subPath(T_PARENT);
ItemPath primaryItemPath;
if (TARGET_NAME.equals(propertyName)) {
primaryItemPath = new ItemPath(AccessCertificationCaseType.F_TARGET_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_NAME);
primaryItemPath = casePath.subPath(AccessCertificationCaseType.F_TARGET_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_NAME);
} else if (OBJECT_NAME.equals(propertyName)) {
primaryItemPath = new ItemPath(AccessCertificationCaseType.F_OBJECT_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_NAME);
primaryItemPath = casePath.subPath(AccessCertificationCaseType.F_OBJECT_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_NAME);
} else if (TENANT_NAME.equals(propertyName)) {
primaryItemPath = new ItemPath(AccessCertificationCaseType.F_TENANT_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_NAME);
primaryItemPath = casePath.subPath(AccessCertificationCaseType.F_TENANT_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_NAME);
} else if (ORG_NAME.equals(propertyName)) {
primaryItemPath = new ItemPath(AccessCertificationCaseType.F_ORG_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_NAME);
primaryItemPath = casePath.subPath(AccessCertificationCaseType.F_ORG_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_NAME);
} else if (CURRENT_REVIEW_DEADLINE.equals(propertyName)) {
primaryItemPath = casePath.subPath(AccessCertificationCaseType.F_CURRENT_REVIEW_DEADLINE);
} else if (CURRENT_REVIEW_REQUESTED_TIMESTAMP.equals(propertyName)) {
primaryItemPath = casePath.subPath(AccessCertificationCaseType.F_CURRENT_REVIEW_REQUESTED_TIMESTAMP);
} else if (CAMPAIGN_NAME.equals(propertyName)) {
primaryItemPath = campaignPath.subPath(ObjectType.F_NAME);
} else {
primaryItemPath = new ItemPath(new QName(SchemaConstantsGenerated.NS_COMMON, propertyName));
}
ObjectOrdering primary = ObjectOrdering.createOrdering(primaryItemPath, sortParam.isAscending() ? OrderDirection.ASCENDING : OrderDirection.DESCENDING);
ObjectOrdering secondary = ObjectOrdering.createOrdering(new ItemPath(PrismConstants.T_ID), OrderDirection.ASCENDING); // to avoid random shuffling if first criteria is too vague
ObjectOrdering tertiary = ObjectOrdering.createOrdering(campaignPath.subPath(PrismConstants.T_ID), OrderDirection.ASCENDING); // campaign OID
return Arrays.asList(primary, secondary, tertiary);
List<ObjectOrdering> rv = new ArrayList<>();
rv.add(ObjectOrdering.createOrdering(primaryItemPath, sortParam.isAscending() ? OrderDirection.ASCENDING : OrderDirection.DESCENDING));
// additional criteria are used to avoid random shuffling if first criteria is too vague)
rv.add(ObjectOrdering.createOrdering(campaignPath.subPath(PrismConstants.T_ID), OrderDirection.ASCENDING)); // campaign OID
rv.add(ObjectOrdering.createOrdering(casePath.subPath(PrismConstants.T_ID), OrderDirection.ASCENDING)); // case ID
if (isWorkItem) {
rv.add(ObjectOrdering.createOrdering(new ItemPath(PrismConstants.T_ID), OrderDirection.ASCENDING)); // work item ID
}
return rv;
}
}
Expand Up @@ -59,6 +59,7 @@ public class LoggingDto implements Serializable {
LoggingComponentType.RESOURCEOBJECTCHANGELISTENER);
componentMap.put("com.evolveum.midpoint.wf", LoggingComponentType.WORKFLOWS);
componentMap.put("com.evolveum.midpoint.notifications", LoggingComponentType.NOTIFICATIONS);
componentMap.put("com.evolveum.midpoint.certification", LoggingComponentType.ACCESS_CERTIFICATION);
}

private LoggingLevelType rootLevel;
Expand Down
Expand Up @@ -54,7 +54,7 @@ public Map<String, String> getNamespaceMap() {
}

public ItemPath() {
segments = new ArrayList<ItemPathSegment>(0);
segments = new ArrayList<>(0);
}

public ItemPath(QName... qnames) {
Expand Down Expand Up @@ -131,6 +131,12 @@ public ItemPath(List<ItemPathSegment> segments, QName subName) {
add(subName);
}

public ItemPath(List<ItemPathSegment> segments, List<ItemPathSegment> additionalSegments) {
this.segments = new ArrayList<>(segments.size()+additionalSegments.size());
this.segments.addAll(segments);
this.segments.addAll(additionalSegments);
}

public ItemPath(ItemPathSegment... segments) {
this.segments = new ArrayList<>(segments.length);
Collections.addAll(this.segments, segments);
Expand All @@ -146,6 +152,10 @@ public ItemPath subPath(QName subName) {
return new ItemPath(segments, subName);
}

public ItemPath subPath(Object... components) {
return new ItemPath(segments, new ItemPath(components).segments);
}

public ItemPath subPath(Long id) {
return subPath(new IdItemPathSegment(id));
}
Expand Down Expand Up @@ -273,7 +283,8 @@ public ItemPath allUpToLastNamed() {
* counted from backwards.
* If the segment is not present, returns empty path.
*/
public ItemPath allUpTo(ItemPathSegment segment) {
@SuppressWarnings("unused")
public ItemPath allUpTo(ItemPathSegment segment) {
int i = segments.lastIndexOf(segment);
if (i < 0) {
return EMPTY_PATH;
Expand Down Expand Up @@ -386,6 +397,7 @@ public static boolean isNullOrEmpty(ItemPath itemPath) {
return itemPath == null || itemPath.isEmpty();
}

@SuppressWarnings("unused")
public static boolean containsSingleNameSegment(ItemPath path) {
return path != null && path.size() == 1 && path.first() instanceof NameItemPathSegment;
}
Expand All @@ -399,11 +411,9 @@ public boolean startsWith(ItemPath other) {
}

public boolean startsWithName(QName name) {
if (!isEmpty() && startsWith(NameItemPathSegment.class)) {
return QNameUtil.match(name, ((NameItemPathSegment) first()).getName());
} else {
return false;
}
return !isEmpty()
&& startsWith(NameItemPathSegment.class)
&& QNameUtil.match(name, ((NameItemPathSegment) first()).getName());
}

public boolean startsWithVariable() {
Expand Down Expand Up @@ -455,10 +465,7 @@ public static List<ItemPath> fromStringList(List<String> pathsAsStrings) {
}

public enum CompareResult {
EQUIVALENT,
SUPERPATH,
SUBPATH,
NO_RELATION;
EQUIVALENT, SUPERPATH, SUBPATH, NO_RELATION
}

public boolean isSubPath(ItemPath otherPath) {
Expand All @@ -476,9 +483,6 @@ public boolean isSubPathOrEquivalent(ItemPath otherPath) {

/**
* Compares two paths semantically.
*
* @param otherPath
* @return
*/
public boolean equivalent(ItemPath otherPath) {
return compareComplex(otherPath) == CompareResult.EQUIVALENT;
Expand Down Expand Up @@ -509,9 +513,6 @@ public ItemPath substract(ItemPath otherPath) {
* Returns the remainder of "this" path after passing all segments from the other path.
* (I.e. this path must begin with the content of the other path. Throws an exception when
* it is not the case.)
*
* @param otherPath
* @return
*/
public ItemPath remainder(ItemPath otherPath) {
ItemPath thisNormalized = this.normalize();
Expand All @@ -535,7 +536,7 @@ public ItemPath remainder(ItemPath otherPath) {

/**
* Convenience static method with checks
* @throw IllegalArgumentException
* @throws IllegalArgumentException If the argument is an item path segment other than a named one
*/
public static QName getName(ItemPathSegment segment) {
if (segment == null) {
Expand Down Expand Up @@ -642,9 +643,6 @@ public boolean equals(Object obj, boolean exact) {
* nor approximate matching QNames via QNameUtil.match.
*
* For semantic-level comparison, please use equivalent(..) method.
*
* @param obj
* @return
*/
@Override
public boolean equals(Object obj) {
Expand Down
Expand Up @@ -147,6 +147,7 @@ LoggingComponentType.REPOSITORY=Repository logger
LoggingComponentType.RESOURCEOBJECTCHANGELISTENER=Resource object change listener logger
LoggingComponentType.TASKMANAGER=Task manager logger
LoggingComponentType.WORKFLOWS = Workflow logger
LoggingComponentType.ACCESS_CERTIFICATION = Access certification logger
LoggingLevelType.ALL=All
LoggingLevelType.DEBUG=Debug
LoggingLevelType.ERROR=Error
Expand Down
Expand Up @@ -11113,6 +11113,13 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="ACCESS_CERTIFICATION">
<xsd:annotation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="ACCESS_CERTIFICATION"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

Expand Down
Expand Up @@ -1040,10 +1040,48 @@ public void test142QueryUserAccountRefNull() throws Exception {
ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext)
.item(UserType.F_LINK_REF).isNull()
.build();
getInterpretedQuery2(session, UserType.class, query);
fail("isNull query for multivalued reference should fail, but it has not.");
} catch (QueryException e) {
// ok
String real = getInterpretedQuery2(session, UserType.class, query);
String expected = "select\n"
+ " u.fullObject,\n"
+ " u.stringsCount,\n"
+ " u.longsCount,\n"
+ " u.datesCount,\n"
+ " u.referencesCount,\n"
+ " u.polysCount,\n"
+ " u.booleansCount\n"
+ "from\n"
+ " RUser u\n"
+ " left join u.linkRef l\n"
+ "where\n"
+ " l is null";
assertEqualsIgnoreWhitespace(expected, real);
} finally {
close(session);
}
}

@Test
public void test144QueryUserAccountRefNotNull() throws Exception {
Session session = open();
try {
ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext)
.not().item(UserType.F_LINK_REF).isNull()
.build();
String real = getInterpretedQuery2(session, UserType.class, query);
String expected = "select\n"
+ " u.fullObject,\n"
+ " u.stringsCount,\n"
+ " u.longsCount,\n"
+ " u.datesCount,\n"
+ " u.referencesCount,\n"
+ " u.polysCount,\n"
+ " u.booleansCount\n"
+ "from\n"
+ " RUser u\n"
+ " left join u.linkRef l\n"
+ "where\n"
+ " not l is null";
assertEqualsIgnoreWhitespace(expected, real);
} finally {
close(session);
}
Expand Down Expand Up @@ -1371,8 +1409,6 @@ public void test310CountObjectOrderByNameWithoutFilter() throws Exception {

/**
* Q{AND: (EQUALS: parent, PPV(null)),PAGING: O: 0,M: 5,BY: name, D:ASCENDING,
*
* @throws Exception
*/
@Test
public void test320CountTaskOrderByName() throws Exception {
Expand Down Expand Up @@ -3307,8 +3343,6 @@ public void test900EqualsMultivalue() throws Exception {
/*
* ### User: preferredLanguage = 'SK', 'HU'
*/
PrismObjectDefinition<UserType> userDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);

PrismPropertyDefinitionImpl<String> multivalDef = new PrismPropertyDefinitionImpl<>(UserType.F_PREFERRED_LANGUAGE,
DOMUtil.XSD_STRING, prismContext);
multivalDef.setMaxOccurs(-1);
Expand Down Expand Up @@ -3676,22 +3710,7 @@ public void testAdHoc102NullRefSingle() throws Exception {
+ "from\n"
+ " RResource r\n"
+ "where\n"
+ " r.connectorRef.targetOid is null";
assertEqualsIgnoreWhitespace(expected, real);
} finally {
close(session);
}
}

@Test(enabled = false)
public void testAdHoc103NullRefMulti() throws Exception {
Session session = open();
try {
ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext)
.item(UserType.F_LINK_REF).isNull()
.build();
String real = getInterpretedQuery2(session, UserType.class, query);
String expected = "";
+ " r.connectorRef is null";
assertEqualsIgnoreWhitespace(expected, real);
} finally {
close(session);
Expand Down
Expand Up @@ -72,11 +72,7 @@ public Condition interpretInternal() throws QueryException {

List<PrismReferenceValue> values = filter.getValues();
if (CollectionUtils.isEmpty(values)) {
if (linkDefinition.getCollectionSpecification() != null) {
// TODO implement
throw new QueryException("'isNull' conditions on multivalued references are not supported: " + linkDefinition);
}
return hibernateQuery.createIsNull(getTargetOidPropertyName());
return hibernateQuery.createIsNull(hqlDataInstance.getHqlPath());
}
Set<String> oids = new HashSet<>();
Set<QName> relations = new HashSet<>();
Expand Down

0 comments on commit 655cae9

Please sign in to comment.