use of com.evolveum.midpoint.repo.sqale.jsonb.Jsonb in project midpoint by Evolveum.
the class QShadowMapping method addIndexOnlyAttributes.
private void addIndexOnlyAttributes(ShadowType shadowType, Tuple row, QShadow entityPath, List<SelectorOptions<GetOperationOptions>> retrieveOptions) throws SchemaException {
Jsonb rowAttributes = row.get(entityPath.attributes);
if (rowAttributes == null) {
return;
}
Map<String, Object> attributes = Jsonb.toMap(rowAttributes);
if (attributes.isEmpty()) {
return;
}
ShadowAttributesType attributeContainer = shadowType.getAttributes();
if (attributeContainer == null) {
attributeContainer = new ShadowAttributesType(prismContext());
shadowType.attributes(attributeContainer);
}
// noinspection unchecked
PrismContainerValue<ShadowAttributesType> container = attributeContainer.asPrismContainerValue();
// Now we retrieve indexOnly options
for (Entry<String, Object> attribute : attributes.entrySet()) {
@Nullable MExtItem mapping = repositoryContext().getExtensionItem(Integer.valueOf(attribute.getKey()));
QName itemName = QNameUtil.uriToQName(mapping.itemName);
ItemDefinition<?> definition = definitionFrom(itemName, mapping, true);
if (definition instanceof PrismPropertyDefinition) {
var item = container.findOrCreateProperty((PrismPropertyDefinition) definition);
switch(mapping.cardinality) {
case SCALAR:
item.setRealValue(attribute.getValue());
break;
case ARRAY:
List<?> value = (List<?>) attribute.getValue();
item.setRealValues(value.toArray());
break;
default:
throw new IllegalStateException("");
}
if (item.isIncomplete() && (item.getDefinition() == null || !item.getDefinition().isIndexOnly())) {
// Item was not fully serialized / probably indexOnly item
item.applyDefinition((PrismPropertyDefinition) definition);
}
item.setIncomplete(false);
}
}
}
use of com.evolveum.midpoint.repo.sqale.jsonb.Jsonb in project midpoint by Evolveum.
the class SqaleRepoSmokeTest method test900WorkingWithPgArraysJsonbAndBytea.
// region low-level tests
/**
* This tests our type mapper/converter classes and related column mapping.
*/
@Test
public void test900WorkingWithPgArraysJsonbAndBytea() {
QUser u = aliasFor(QUser.class);
MUser user = new MUser();
String userName = "user" + getTestNumber();
setName(user, userName);
user.policySituations = new Integer[] { 1, 2 };
user.subtypes = new String[] { "subtype1", "subtype2" };
// more whitespaces/lines
user.ext = new Jsonb("{\"key\" : \"value\",\n\"number\": 47} ");
user.photo = new byte[] { 0, 1, 0, 1 };
try (JdbcSession jdbcSession = startTransaction()) {
jdbcSession.newInsert(u).populate(user).execute();
jdbcSession.commit();
}
MUser row = selectOne(u, u.nameNorm.eq(userName));
assertThat(row.policySituations).contains(1, 2);
assertThat(row.subtypes).contains("subtype1", "subtype2");
// normalized
assertThat(row.ext.value).isEqualTo("{\"key\": \"value\", \"number\": 47}");
// byte[] is used for fullObject, there is no chance to miss a problem with it
assertThat(row.photo).hasSize(4);
// setting NULLs
try (JdbcSession jdbcSession = startTransaction()) {
jdbcSession.newUpdate(u).setNull(u.policySituations).set(u.subtypes, // this should do the same
(String[]) null).setNull(u.ext).setNull(u.photo).where(u.oid.eq(row.oid)).execute();
jdbcSession.commit();
}
row = selectOne(u, u.nameNorm.eq(userName));
assertThat(row.policySituations).isNull();
assertThat(row.subtypes).isNull();
assertThat(row.ext).isNull();
// but we never set fullObject to null, so this is a good test for doing so with byte[]
assertThat(row.photo).isNull();
}
use of com.evolveum.midpoint.repo.sqale.jsonb.Jsonb in project midpoint by Evolveum.
the class QShadowMapping method toSchemaObject.
@Override
public ShadowType toSchemaObject(Tuple row, QShadow entityPath, Collection<SelectorOptions<GetOperationOptions>> options) throws SchemaException {
ShadowType shadowType = super.toSchemaObject(row, entityPath, options);
// FIXME: we store it because provisioning now sends it to repo, but it should be transient
shadowType.asPrismObject().removeContainer(ShadowType.F_ASSOCIATION);
GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
if (GetOperationOptions.isRaw(rootOptions)) {
// If raw=true, we populate attributes with types cached in repository
Jsonb rowAttributes = row.get(entityPath.attributes);
applyShadowAttributesDefinitions(shadowType, rowAttributes);
}
List<SelectorOptions<GetOperationOptions>> retrieveOptions = SelectorOptions.filterRetrieveOptions(options);
if (retrieveOptions.isEmpty()) {
return shadowType;
}
if (loadIndexOnly(retrieveOptions)) {
addIndexOnlyAttributes(shadowType, row, entityPath, retrieveOptions);
}
return shadowType;
}
Aggregations