Skip to content

Commit

Permalink
Make language (XML/JSON) for repo configurable
Browse files Browse the repository at this point in the history
JSON should be a lot faster to process. Note it does not work
reliably now.
  • Loading branch information
mederly committed Dec 13, 2018
1 parent 245d69b commit 1c17d68
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
Expand Up @@ -53,6 +53,7 @@
import java.io.File;
import java.util.*;

import static com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext;
import static org.testng.AssertJUnit.*;

/**
Expand Down Expand Up @@ -328,7 +329,9 @@ public void addGetFullAccount() throws Exception {
ObjectDelta<ShadowType> delta = fileAccount.diff(repoAccount);
AssertJUnit.assertNotNull(delta);
LOGGER.info("delta\n{}", new Object[]{delta.debugDump(3)});
assertTrue(delta.isEmpty());
if (!delta.isEmpty()) {
fail("delta is not empty: " + delta.debugDump());
}
ShadowType repoShadow = repoAccount.asObjectable();
AssertJUnit.assertNotNull(repoShadow.getSynchronizationSituation());
AssertJUnit.assertEquals(SynchronizationSituationType.LINKED, repoShadow.getSynchronizationSituation());
Expand Down Expand Up @@ -775,7 +778,7 @@ public void test300ContainerIds() throws Exception {
public void test990AddResourceWithEmptyConnectorConfiguration() throws Exception {
OperationResult result = new OperationResult("test990AddResourceWithEmptyConnectorConfiguration");

PrismObject<ResourceType> prismResource = PrismTestUtil.getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ResourceType.class).instantiate();
PrismObject<ResourceType> prismResource = getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ResourceType.class).instantiate();

PolyStringType name = new PolyStringType();
name.setOrig("Test Resource");
Expand Down Expand Up @@ -826,7 +829,7 @@ public void test400AddModifyTask() throws Exception {
AssertJUnit.assertEquals(ROperationResultStatus.IN_PROGRESS, rTask.getStatus());

String xml = RUtil.getXmlFromByteArray(rTask.getFullObject(), true);
PrismObject<TaskType> obj = PrismTestUtil.parseObject(xml);
PrismObject<TaskType> obj = getPrismContext().parserFor(xml).language(SqlRepositoryServiceImpl.DATA_LANGUAGE).parse();
TaskType objType = obj.asObjectable();
AssertJUnit.assertNull(objType.getResult());
} finally {
Expand Down
Expand Up @@ -329,7 +329,7 @@ private <X extends ObjectType> PrismObject<X> resolve(Session session, String oi
PrismObject result;
if (object != null) {
String xml = RUtil.getXmlFromByteArray(object.getFullObject(), getConfiguration().isUseZip());
result = getPrismContext().parserFor(xml).compat().parse();
result = getPrismContext().parserFor(xml).language(SqlRepositoryServiceImpl.DATA_LANGUAGE).compat().parse();
} else if (defaultType != null) {
result = getPrismContext().createObject(defaultType.getJaxbClass());
result.asObjectable().setName(PolyStringType.fromOrig(defaultName != null ? defaultName : oid));
Expand Down
Expand Up @@ -94,6 +94,9 @@
@Repository
public class SqlRepositoryServiceImpl extends SqlBaseService implements RepositoryService {

// experimental (currently some tests fail when using JSON)
public static final String DATA_LANGUAGE = PrismContext.LANG_XML;

public static final String PERFORMANCE_LOG_NAME = SqlRepositoryServiceImpl.class.getName() + ".performance";
public static final String CONTENTION_LOG_NAME = SqlRepositoryServiceImpl.class.getName() + ".contention";
public static final int CONTENTION_LOG_DEBUG_THRESHOLD = 3;
Expand Down
Expand Up @@ -18,6 +18,7 @@

import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.repo.sql.SqlRepositoryServiceImpl;
import com.evolveum.midpoint.repo.sql.data.RepositoryContext;
import com.evolveum.midpoint.repo.sql.data.common.RAccessCertificationCampaign;
import com.evolveum.midpoint.repo.sql.data.common.embedded.RActivation;
Expand Down Expand Up @@ -356,7 +357,7 @@ private static RAccessCertificationCase toRepo(RAccessCertificationCase rCase, A
PrismContainerValue<AccessCertificationCaseType> cvalue = case1.asPrismContainerValue();
String xml;
try {
xml = context.prismContext.xmlSerializer().serialize(cvalue, SchemaConstantsGenerated.C_VALUE);
xml = context.prismContext.serializerFor(SqlRepositoryServiceImpl.DATA_LANGUAGE).serialize(cvalue, SchemaConstantsGenerated.C_VALUE);
} catch (SchemaException e) {
throw new IllegalStateException("Couldn't serialize certification case to string", e);
}
Expand All @@ -376,7 +377,7 @@ public static AccessCertificationCaseType createJaxb(byte[] fullObject, PrismCon
String xml = RUtil.getXmlFromByteArray(fullObject, false);
LOGGER.trace("RAccessCertificationCase full object to be parsed\n{}", xml);
try {
return prismContext.parserFor(xml).xml().compat().parseRealValue(AccessCertificationCaseType.class);
return prismContext.parserFor(xml).language(SqlRepositoryServiceImpl.DATA_LANGUAGE).compat().parseRealValue(AccessCertificationCaseType.class);
} catch (SchemaException e) {
LOGGER.debug("Couldn't parse certification case because of schema exception ({}):\nData: {}", e, xml);
throw e;
Expand Down
Expand Up @@ -513,7 +513,7 @@ private <T extends ObjectType> PrismObject<T> updateLoadedObject(GetObjectResult
try {
// "Postel mode": be tolerant what you read. We need this to tolerate (custom) schema changes
ParsingContext parsingContext = prismContext.createParsingContextForCompatibilityMode();
prismObject = prismContext.parserFor(xml).context(parsingContext).parse();
prismObject = prismContext.parserFor(xml).language(SqlRepositoryServiceImpl.DATA_LANGUAGE).context(parsingContext).parse();
if (parsingContext.hasWarnings()) {
LOGGER.warn("Object {} parsed with {} warnings", ObjectTypeUtil.toShortString(prismObject), parsingContext.getWarnings().size());
// TODO enable if needed
Expand Down
Expand Up @@ -247,7 +247,7 @@ public <T extends ObjectType> void updateFullObject(RObject object, PrismObject<
savedObject.removeProperty(TaskType.F_RESULT);
}

xml = prismContext.xmlSerializer().serialize(savedObject);
xml = prismContext.serializerFor(SqlRepositoryServiceImpl.DATA_LANGUAGE).serialize(savedObject);
byte[] fullObject = RUtil.getByteArrayFromXml(xml, getConfiguration().isUseZip());

object.setFullObject(fullObject);
Expand Down

0 comments on commit 1c17d68

Please sign in to comment.