Skip to content

Commit

Permalink
Minor enhancements.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Aug 15, 2016
1 parent d0c1e5e commit 79d6358
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
Expand Up @@ -124,6 +124,11 @@ public S_MatchingRuleEntry eqPoly(String orig, String norm) {
return new R_AtomicFilter(this, EqualFilter.createEqual(itemPath, propertyDefinition, null, new PolyString(orig, norm)));
}

@Override
public S_MatchingRuleEntry eqPoly(String orig) {
return new R_AtomicFilter(this, EqualFilter.createEqual(itemPath, propertyDefinition, null, new PolyString(orig)));
}

@Override
public S_MatchingRuleEntry gt(Object value) throws SchemaException {
return new R_AtomicFilter(this, GreaterFilter.createGreater(itemPath, propertyDefinition, value, false));
Expand Down
Expand Up @@ -29,6 +29,7 @@ public interface S_ConditionEntry {
S_MatchingRuleEntry eq(Object... values);
S_RightHandItemEntry eq();
S_MatchingRuleEntry eqPoly(String orig, String norm);
S_MatchingRuleEntry eqPoly(String orig);
S_MatchingRuleEntry gt(Object value) throws SchemaException;
S_RightHandItemEntry gt();
S_MatchingRuleEntry ge(Object value) throws SchemaException;
Expand Down
Expand Up @@ -22,29 +22,19 @@
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.util.ItemPathUtil;
import com.evolveum.midpoint.prism.xml.GlobalDynamicNamespacePrefixMapper;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.JAXBUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import com.evolveum.prism.xml.ns._public.types_3.ModificationTypeType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType;

import org.apache.commons.lang.Validate;
import org.w3c.dom.Document;
import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Element;

import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -191,6 +181,32 @@ public static String getShortTypeName(Class<? extends ObjectType> type) {
}
}

@NotNull
public static <T extends ObjectType> AssignmentType createAssignmentTo(@NotNull ObjectReferenceType ref) {
AssignmentType assignment = new AssignmentType();
if (QNameUtil.match(ref.getType(), ResourceType.COMPLEX_TYPE)) {
ConstructionType construction = new ConstructionType();
construction.setResourceRef(ref);
assignment.setConstruction(construction);
} else {
assignment.setTargetRef(ref);
}
return assignment;
}

@NotNull
public static <T extends ObjectType> AssignmentType createAssignmentTo(@NotNull PrismObject<T> object) {
AssignmentType assignment = new AssignmentType(object.getPrismContext());
if (object.asObjectable() instanceof ResourceType) {
ConstructionType construction = new ConstructionType(object.getPrismContext());
construction.setResourceRef(createObjectRef(object));
assignment.setConstruction(construction);
} else {
assignment.setTargetRef(createObjectRef(object));
}
return assignment;
}

public static ObjectReferenceType createObjectRef(PrismReferenceValue prv) {
ObjectReferenceType ort = new ObjectReferenceType();
ort.setupReferenceValue(prv);
Expand Down
Expand Up @@ -246,14 +246,10 @@ public void test010QueryOrganizationNorm() throws Exception {

try {
/*
* ### user: Equal (organization, "asdf", PolyStringNorm)
* ### user: Equal (organization, "...", PolyStringNorm)
*/
ObjectFilter filter = EqualFilter.createEqual(UserType.F_ORGANIZATION, UserType.class, prismContext,
PolyStringNormMatchingRule.NAME, new PolyString("asdf", "asdf"));
ObjectQuery query0 = ObjectQuery.createObjectQuery(filter);

ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext)
.item(UserType.F_ORGANIZATION).eqPoly("asdf", "asdf").matchingNorm().build();
.item(UserType.F_ORGANIZATION).eqPoly("guľôčka v jamôčke").matchingNorm().build();

String expected = "select\n" +
" u.fullObject, u.stringsCount, u.longsCount, u.datesCount, u.referencesCount, u.polysCount, u.booleansCount\n" +
Expand All @@ -263,8 +259,11 @@ public void test010QueryOrganizationNorm() throws Exception {
"where\n" +
" o.norm = :norm";

String real = getInterpretedQuery2(session, UserType.class, query);
RQueryImpl rQuery = (RQueryImpl) getInterpretedQuery2Whole(session, UserType.class, query, false);
String real = rQuery.getQuery().getQueryString();
assertEqualsIgnoreWhitespace(expected, real);

assertEquals("Wrong parameter value", "gulocka v jamocke", rQuery.getQuerySource().getParameters().get("norm").getValue());
} finally {
close(session);
}
Expand Down

0 comments on commit 79d6358

Please sign in to comment.