Skip to content

Commit

Permalink
Add support for ObjectCollectionType (MID-4755)
Browse files Browse the repository at this point in the history
But without DB scripts for now.
  • Loading branch information
mederly committed Jun 21, 2018
1 parent a4ecf48 commit e66c46d
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 2 deletions.
Expand Up @@ -81,7 +81,9 @@ public enum ObjectTypeGuiDescriptor {

CASE(ObjectTypes.CASE, "ObjectTypeGuiDescriptor.case", "", ""), // TODO icons

FUNCTION_LIBRARY(ObjectTypes.FUNCTION_LIBRARY, "ObjectTypeGuiDescriptor.functionLibrary", "", ""); // TODO icons
FUNCTION_LIBRARY(ObjectTypes.FUNCTION_LIBRARY, "ObjectTypeGuiDescriptor.functionLibrary", "", ""), // TODO icons

OBJECT_COLLECTION(ObjectTypes.OBJECT_COLLECTION, "ObjectTypeGuiDescriptor.objectCollection", "", ""); // TODO icons

public static final String ERROR_ICON = "silk-error";
public static final String ERROR_LOCALIZATION_KEY = "ObjectTypeGuiDescriptor.unknown";
Expand Down
Expand Up @@ -669,6 +669,7 @@ ObjectTypeGuiDescriptor.service=Service
ObjectTypeGuiDescriptor.case=Case
ObjectTypeGuiDescriptor.valuePolicy=Value policy
ObjectTypeGuiDescriptor.functionLibrary=Function library
ObjectTypeGuiDescriptor.objectCollection=Object collection
ObjectTypeGuiDescriptor.unknown=Not defined
operation.com.evolveum.midpoint.common.crypto.CryptoUtil.securitySelfTest=Security self test
operation.com.evolveum.midpoint.common.operation.import.object=Import object
Expand Down
Expand Up @@ -24,7 +24,10 @@
import com.evolveum.midpoint.prism.delta.ReferenceDelta;
import com.evolveum.midpoint.prism.delta.builder.DeltaBuilder;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.QueryJaxbConvertor;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.prism.query.builder.QueryBuilder;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
Expand Down Expand Up @@ -52,6 +55,7 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;
import com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.hibernate.Session;
Expand Down Expand Up @@ -930,4 +934,57 @@ private <T> void assertAttribute(PrismObject<ShadowType> shadow, QName attrQName
PrismAsserts.assertPropertyValue(attr, expectedValues);
}
}

@Test
public void test210ModifyObjectCollection() throws Exception {
final String TEST_NAME = "test210ModifyObjectCollection";
TestUtil.displayTestTitle(TEST_NAME);

OperationResult result = new OperationResult("test210ModifyObjectCollection");

ObjectCollectionType collection = prismContext.createObjectable(ObjectCollectionType.class)
.name("collection")
.type(UserType.COMPLEX_TYPE);
repositoryService.addObject(collection.asPrismObject(), null, result);

List<ItemDelta<?, ?>> deltas1 = DeltaBuilder.deltaFor(ObjectCollectionType.class, prismContext)
.item(ObjectCollectionType.F_NAME).replace(PolyString.fromOrig("collection2"))
.asItemDeltas();
repositoryService.modifyObject(ObjectCollectionType.class, collection.getOid(), deltas1, result);

ItemDelta.applyTo(deltas1, collection.asPrismObject());
PrismObject<ObjectCollectionType> afterChange1 = repositoryService
.getObject(ObjectCollectionType.class, collection.getOid(), null, result);
assertEquals("Objects differ after change 1", collection.asPrismObject(), afterChange1);

ObjectFilter filter = QueryBuilder.queryFor(UserType.class, prismContext)
.item(UserType.F_COST_CENTER).eq("100")
.buildFilter();
SearchFilterType filterBean = QueryJaxbConvertor.createSearchFilterType(filter, prismContext);

List<ItemDelta<?, ?>> deltas2 = DeltaBuilder.deltaFor(ObjectCollectionType.class, prismContext)
.item(ObjectCollectionType.F_DESCRIPTION).replace("description")
.item(ObjectCollectionType.F_FILTER).replace(filterBean)
.asItemDeltas();
repositoryService.modifyObject(ObjectCollectionType.class, collection.getOid(), deltas2, result);

ItemDelta.applyTo(deltas2, collection.asPrismObject());
PrismObject<ObjectCollectionType> afterChange2 = repositoryService
.getObject(ObjectCollectionType.class, collection.getOid(), null, result);

// it's hard to compare filters, so we have to do the test in a special way
PrismObject<ObjectCollectionType> fromRepoWithoutFilter = afterChange2.clone();
fromRepoWithoutFilter.asObjectable().setFilter(null);
PrismObject<ObjectCollectionType> expectedWithoutFilter = collection.asPrismObject().clone();
expectedWithoutFilter.asObjectable().setFilter(null);
assertEquals("Objects (without filter) differ after change 2", expectedWithoutFilter, fromRepoWithoutFilter);

SearchFilterType filterFromRepo = afterChange2.asObjectable().getFilter();
SearchFilterType filterExpected = collection.getFilter();
ObjectFilter filterFromRepoParsed = QueryJaxbConvertor.createObjectFilter(UserType.class, filterFromRepo, prismContext);
ObjectFilter filterExpectedParsed = QueryJaxbConvertor.createObjectFilter(UserType.class, filterExpected, prismContext);
//noinspection ConstantConditions
assertTrue("Filters differ", filterExpectedParsed.equals(filterFromRepoParsed, false));
}

}
Expand Up @@ -911,4 +911,24 @@ public void testExtensionReferenceNonNull() throws SchemaException {
assertEquals("Should find 1 object", 1, cases.size());
}

@Test
public void testObjectCollection() throws SchemaException {
ObjectQuery query = QueryBuilder.queryFor(ObjectCollectionType.class, prismContext)
.item(ObjectType.F_NAME).eqPoly("collection1", "collection1").matchingOrig()
.build();
OperationResult result = new OperationResult("search");
List<PrismObject<ObjectCollectionType>> collections = repositoryService.searchObjects(ObjectCollectionType.class, query, null, result);
result.recomputeStatus();
assertTrue(result.isSuccess());
assertEquals("Should find 1 object", 1, collections.size());
}

@Test
public void testAllObjectCollections() throws SchemaException {
OperationResult result = new OperationResult("search");
List<PrismObject<ObjectCollectionType>> collections = repositoryService.searchObjects(ObjectCollectionType.class, null, null, result);
result.recomputeStatus();
assertTrue(result.isSuccess());
assertEquals("Should find 1 object", 1, collections.size());
}
}
11 changes: 11 additions & 0 deletions repo/repo-sql-impl-test/src/test/resources/basic/objects.xml
Expand Up @@ -1696,4 +1696,15 @@
</operationExecution>
</case>

<objectCollection>
<name>collection1</name>
<type>UserType</type>
<filter>
<q:equal>
<q:path>subtype</q:path>
<q:value>EMP</q:value>
</q:equal>
</filter>
</objectCollection>

</objects>
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2010-2018 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.repo.sql.data.common;

import com.evolveum.midpoint.repo.sql.data.RepositoryContext;
import com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString;
import com.evolveum.midpoint.repo.sql.query.definition.JaxbName;
import com.evolveum.midpoint.repo.sql.util.DtoTranslationException;
import com.evolveum.midpoint.repo.sql.util.IdGeneratorResult;
import com.evolveum.midpoint.repo.sql.util.MidPointJoinedPersister;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectCollectionType;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Persister;

import javax.persistence.*;
import java.util.Objects;

/**
*
* @author mederly
*/
@Entity
@ForeignKey(name = "fk_object_collection")
@Table(uniqueConstraints = @UniqueConstraint(name = "uc_object_collection_name", columnNames = {"name_norm"}),
indexes = {
@Index(name = "iObjectCollectionNameOrig", columnList = "name_orig"),
}
)
@Persister(impl = MidPointJoinedPersister.class)
public class RObjectCollection extends RObject<ObjectCollectionType> {

private RPolyString nameCopy;

@JaxbName(localPart = "name")
@AttributeOverrides({
@AttributeOverride(name = "orig", column = @Column(name = "name_orig")),
@AttributeOverride(name = "norm", column = @Column(name = "name_norm"))
})
@Embedded
public RPolyString getNameCopy() {
return nameCopy;
}

public void setNameCopy(RPolyString nameCopy) {
this.nameCopy = nameCopy;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof RObjectCollection))
return false;
if (!super.equals(o))
return false;
RObjectCollection that = (RObjectCollection) o;
return Objects.equals(nameCopy, that.nameCopy);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), nameCopy);
}

public static void copyFromJAXB(ObjectCollectionType jaxb, RObjectCollection repo, RepositoryContext repositoryContext,
IdGeneratorResult generatorResult) throws DtoTranslationException {
RObject.copyFromJAXB(jaxb, repo, repositoryContext, generatorResult);
repo.setNameCopy(RPolyString.copyFromJAXB(jaxb.getName()));
}
}
Expand Up @@ -34,7 +34,8 @@ public enum RObjectType {
SERVICE(RService.class, ServiceType.class),
FORM(RForm.class, FormType.class),
CASE(RCase.class, CaseType.class),
FUNCTION_LIBRARY(RFunctionLibrary.class, FunctionLibraryType.class);
FUNCTION_LIBRARY(RFunctionLibrary.class, FunctionLibraryType.class),
OBJECT_COLLECTION(RObjectCollection.class, ObjectCollectionType.class);

private Class<? extends RObject> clazz;
private Class<? extends ObjectType> jaxbClass;
Expand Down
Expand Up @@ -69,6 +69,7 @@ private ClassMapper() {
types.put(ObjectTypes.FORM, RObjectType.FORM);
types.put(ObjectTypes.CASE, RObjectType.CASE);
types.put(ObjectTypes.FUNCTION_LIBRARY, RObjectType.FUNCTION_LIBRARY);
types.put(ObjectTypes.OBJECT_COLLECTION, RObjectType.OBJECT_COLLECTION);

for (ObjectTypes type : ObjectTypes.values()) {
if (!types.containsKey(type)) {
Expand Down

0 comments on commit e66c46d

Please sign in to comment.