use of com.evolveum.midpoint.prism.Item in project midpoint by Evolveum.
the class ReportUtils method getItemRealValue.
public static Object getItemRealValue(PrismContainerValue containerValue, String itemName) {
Item item = containerValue.findItem(new QName(itemName));
if (item == null || item.size() == 0) {
return null;
}
if (item.size() > 1) {
throw new IllegalStateException("More than one value in item " + item);
}
PrismValue value = item.getValue(0);
if (value == null) {
return null;
}
if (value instanceof PrismPropertyValue) {
return ((PrismPropertyValue) value).getValue();
} else if (value instanceof PrismReferenceValue) {
ObjectReferenceType ort = new ObjectReferenceType();
ort.setupReferenceValue((PrismReferenceValue) value);
return ort;
} else if (value instanceof PrismContainerValue) {
// questionable
return ((PrismContainerValue) value).asContainerable();
} else {
throw new IllegalStateException("Unknown PrismValue: " + value);
}
}
use of com.evolveum.midpoint.prism.Item in project midpoint by Evolveum.
the class RAssignmentExtension method copyFromJAXB.
private static void copyFromJAXB(PrismContainerValue containerValue, RAssignmentExtension repo, RAssignmentExtensionType type, RepositoryContext repositoryContext) throws DtoTranslationException {
RAnyConverter converter = new RAnyConverter(repositoryContext.prismContext);
Set<RAnyValue> values = new HashSet<RAnyValue>();
try {
List<Item<?, ?>> items = containerValue.getItems();
for (Item item : items) {
values.addAll(converter.convertToRValue(item, true));
}
} catch (Exception ex) {
throw new DtoTranslationException(ex.getMessage(), ex);
}
for (RAnyValue value : values) {
((RAExtValue) value).setAnyContainer(repo);
((RAExtValue) value).setExtensionType(type);
if (value instanceof RAExtDate) {
repo.getDates().add((RAExtDate) value);
} else if (value instanceof RAExtLong) {
repo.getLongs().add((RAExtLong) value);
} else if (value instanceof RAExtReference) {
repo.getReferences().add((RAExtReference) value);
} else if (value instanceof RAExtString) {
repo.getStrings().add((RAExtString) value);
} else if (value instanceof RAExtPolyString) {
repo.getPolys().add((RAExtPolyString) value);
} else if (value instanceof RAExtBoolean) {
repo.getBooleans().add((RAExtBoolean) value);
}
}
repo.setStringsCount((short) repo.getStrings().size());
repo.setDatesCount((short) repo.getDates().size());
repo.setPolysCount((short) repo.getPolys().size());
repo.setReferencesCount((short) repo.getReferences().size());
repo.setLongsCount((short) repo.getLongs().size());
repo.setBooleansCount((short) repo.getBooleans().size());
}
use of com.evolveum.midpoint.prism.Item in project midpoint by Evolveum.
the class AbstractIntegrationTest method assertShadowRepo.
protected void assertShadowRepo(PrismObject<ShadowType> accountShadow, String oid, String username, ResourceType resourceType, QName objectClass, MatchingRule<String> nameMatchingRule) throws SchemaException {
assertShadowCommon(accountShadow, oid, username, resourceType, objectClass, nameMatchingRule, true);
PrismContainer<Containerable> attributesContainer = accountShadow.findContainer(ShadowType.F_ATTRIBUTES);
List<Item<?, ?>> attributes = attributesContainer.getValue().getItems();
// Collection secIdentifiers = ShadowUtil.getSecondaryIdentifiers(accountShadow);
if (attributes == null) {
AssertJUnit.fail("No attributes in repo shadow");
}
RefinedResourceSchema refinedSchema = null;
try {
refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType);
} catch (SchemaException e) {
AssertJUnit.fail(e.getMessage());
}
ObjectClassComplexTypeDefinition objClassDef = refinedSchema.getRefinedDefinition(objectClass);
Collection secIdentifiers = objClassDef.getSecondaryIdentifiers();
if (secIdentifiers == null) {
AssertJUnit.fail("No secondary identifiers in repo shadow");
}
// repo shadow should contains all secondary identifiers + ICF_UID
assertRepoShadowAttributes(attributes, secIdentifiers.size() + 1);
}
use of com.evolveum.midpoint.prism.Item in project midpoint by Evolveum.
the class ObjectDeltaObject method findIdi.
@Override
public <IV extends PrismValue, ID extends ItemDefinition> ItemDeltaItem<IV, ID> findIdi(ItemPath path) {
Item<IV, ID> subItemOld = null;
ItemPath subResidualPath = null;
if (oldObject != null) {
PartiallyResolvedItem<IV, ID> partialOld = oldObject.findPartial(path);
if (partialOld != null) {
subItemOld = partialOld.getItem();
subResidualPath = partialOld.getResidualPath();
}
}
Item<IV, ID> subItemNew = null;
if (newObject != null) {
PartiallyResolvedItem<IV, ID> partialNew = newObject.findPartial(path);
if (partialNew != null) {
subItemNew = partialNew.getItem();
if (subResidualPath == null) {
subResidualPath = partialNew.getResidualPath();
}
}
}
ItemDelta<IV, ID> itemDelta = null;
Collection<? extends ItemDelta<?, ?>> subSubItemDeltas = null;
if (delta != null) {
if (delta.getChangeType() == ChangeType.ADD) {
PrismObject<O> objectToAdd = delta.getObjectToAdd();
PartiallyResolvedItem<IV, ID> partialValue = objectToAdd.findPartial(path);
if (partialValue != null && partialValue.getItem() != null) {
Item<IV, ID> item = partialValue.getItem();
itemDelta = item.createDelta();
itemDelta.addValuesToAdd(item.getClonedValues());
} else {
// No item for this path, itemDelta will stay empty.
}
} else if (delta.getChangeType() == ChangeType.DELETE) {
if (subItemOld != null) {
ItemPath subPath = subItemOld.getPath().remainder(path);
PartiallyResolvedItem<IV, ID> partialValue = subItemOld.findPartial(subPath);
if (partialValue != null && partialValue.getItem() != null) {
Item<IV, ID> item = partialValue.getItem();
itemDelta = item.createDelta();
itemDelta.addValuesToDelete(item.getClonedValues());
} else {
// No item for this path, itemDelta will stay empty.
}
}
} else if (delta.getChangeType() == ChangeType.MODIFY) {
for (ItemDelta<?, ?> modification : delta.getModifications()) {
CompareResult compareComplex = modification.getPath().compareComplex(path);
if (compareComplex == CompareResult.EQUIVALENT) {
if (itemDelta != null) {
throw new IllegalStateException("Conflicting modification in delta " + delta + ": " + itemDelta + " and " + modification);
}
itemDelta = (ItemDelta<IV, ID>) modification;
} else if (compareComplex == CompareResult.SUPERPATH) {
if (subSubItemDeltas == null) {
subSubItemDeltas = new ArrayList<>();
}
((Collection) subSubItemDeltas).add(modification);
} else if (compareComplex == CompareResult.SUBPATH) {
if (itemDelta != null) {
throw new IllegalStateException("Conflicting modification in delta " + delta + ": " + itemDelta + " and " + modification);
}
itemDelta = (ItemDelta<IV, ID>) modification.getSubDelta(path.substract(modification.getPath()));
}
}
}
}
ItemDeltaItem<IV, ID> subIdi = new ItemDeltaItem<IV, ID>(subItemOld, itemDelta, subItemNew);
subIdi.setSubItemDeltas(subSubItemDeltas);
subIdi.setResolvePath(path);
subIdi.setResidualPath(subResidualPath);
return subIdi;
}
use of com.evolveum.midpoint.prism.Item in project midpoint by Evolveum.
the class DirectAssignmentCertGuiHandler method getCaseInfoButtonTitle.
@Override
public String getCaseInfoButtonTitle(IModel<? extends CertCaseOrWorkItemDto> rowModel, PageBase page) {
CertCaseOrWorkItemDto dto = rowModel.getObject();
AccessCertificationCaseType _case = dto.getCertCase();
if (!(_case instanceof AccessCertificationAssignmentCaseType)) {
// should not occur, TODO treat gracefully
return null;
}
AccessCertificationAssignmentCaseType assignmentCase = (AccessCertificationAssignmentCaseType) _case;
AssignmentType assignment = assignmentCase.getAssignment();
List<String> infoList = new ArrayList<>();
String assignmentOrInducement;
if (Boolean.TRUE.equals(assignmentCase.isIsInducement())) {
assignmentOrInducement = page.createStringResource("PageCert.message.textInducement").getString();
} else {
assignmentOrInducement = page.createStringResource("PageCert.message.textAssignment").getString();
}
String targetType = getLocalizedTypeName(_case.getTargetRef().getType(), page);
String targetName = dto.getTargetName();
String objectType = getLocalizedTypeName(_case.getObjectRef().getType(), page);
String objectName = dto.getObjectName();
infoList.add(page.createStringResource("PageCert.message.assignment", assignmentOrInducement, emptyToDash(targetType), emptyToDash(targetName), emptyToDash(objectType), emptyToDash(objectName)).getString());
if (StringUtils.isNotEmpty(assignment.getDescription())) {
infoList.add(page.createStringResource("PageCert.message.textDescription", assignment.getDescription()).getString());
}
if (assignment.getOrder() != null) {
infoList.add(page.createStringResource("PageCert.message.textOrder", assignment.getOrder()).getString());
}
if (assignment.getConstruction() != null) {
if (assignment.getConstruction().getKind() != null) {
infoList.add(page.createStringResource("PageCert.message.textKind", page.createStringResource(assignment.getConstruction().getKind()).getString()).getString());
}
if (assignment.getConstruction().getIntent() != null) {
infoList.add(page.createStringResource("PageCert.message.textIntent", assignment.getConstruction().getIntent()).getString());
}
}
if (_case.getTargetRef().getRelation() != null) {
infoList.add(page.createStringResource("PageCert.message.textRelation", _case.getTargetRef().getRelation().getLocalPart()).getString());
}
Task task = page.createSimpleTask("dummy");
if (assignment.getOrgRef() != null) {
String orgName = WebModelServiceUtils.resolveReferenceName(assignment.getOrgRef(), page, task, task.getResult());
infoList.add(page.createStringResource("PageCert.message.textOrg", orgName).getString());
}
if (assignment.getTenantRef() != null) {
String tenantName = WebModelServiceUtils.resolveReferenceName(assignment.getTenantRef(), page, task, task.getResult());
infoList.add(page.createStringResource("PageCert.message.textTenant", tenantName).getString());
}
PrismContainer<? extends Containerable> extensionContainer = assignment.asPrismContainerValue().findContainer(AssignmentType.F_EXTENSION);
if (extensionContainer != null && !extensionContainer.isEmpty()) {
List<String> extensionItemNameList = new ArrayList<>();
for (Item extensionItem : extensionContainer.getValue().getItems()) {
extensionItemNameList.add(extensionItem.getElementName().getLocalPart());
}
infoList.add(page.createStringResource("PageCert.message.textExtensions", StringUtils.join(extensionItemNameList, ", ")).getString());
}
if (assignment.getActivation() != null) {
String validFrom = WebComponentUtil.formatDate(assignment.getActivation().getValidFrom());
if (validFrom != null) {
infoList.add(page.createStringResource("PageCert.message.textValidFrom", validFrom).getString());
}
String validTo = WebComponentUtil.formatDate(assignment.getActivation().getValidTo());
if (validTo != null) {
infoList.add(page.createStringResource("PageCert.message.textValidTo", validTo).getString());
}
if (assignment.getActivation().getAdministrativeStatus() != null) {
infoList.add(page.createStringResource("PageCert.message.textAdministrativeState", page.createStringResource(assignment.getActivation().getAdministrativeStatus()).getString()).getString());
}
}
String rv = StringUtils.join(infoList, "<br/>");
return rv;
}
Aggregations