use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType in project midpoint by Evolveum.
the class ConstructionDetailsPanelChainedModel method initLayout.
private void initLayout() {
CompoundPropertyModel constrModel = new CompoundPropertyModel(getModel()) {
@Override
public Object getObject() {
Object o = super.getObject();
return o;
}
@Override
public void setObject(Object o) {
super.setObject(o);
}
};
Form<ConstructionType> form = new Form<ConstructionType>(ID_FORM, constrModel);
form.setOutputMarkupId(true);
DropDownChoice kindChoice = new DropDownChoice<>("kind", Model.ofList(Arrays.asList(ShadowKindType.values())));
kindChoice.setOutputMarkupId(true);
kindChoice.add(new EmptyOnBlurAjaxFormUpdatingBehaviour() {
@Override
protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
// ajaxRequestTarget.add(form);
}
});
// kindChoice.add(new AjaxEventBehavior("blur") {
// @Override
// protected void onEvent(AjaxRequestTarget ajaxRequestTarget) {
// ajaxRequestTarget.add(form);
// }
// });
form.add(kindChoice);
DropDownChoice intentDropdown = new DropDownChoice<>("intent", new IModel<List<String>>() {
@Override
public List<String> getObject() {
List<String> availableIntentValues = new ArrayList<>();
try {
if (resourceModel.getObject() == null) {
return availableIntentValues;
}
ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(resourceModel.getObject());
if (refinedSchema != null) {
ConstructionType m = (ConstructionType) constrModel.getObject();
ShadowKindType kind = m.getKind();
List<? extends ResourceObjectTypeDefinition> definitions = refinedSchema.getObjectTypeDefinitions(kind);
for (ResourceObjectTypeDefinition def : definitions) {
if (def.getIntent() != null) {
availableIntentValues.add(def.getIntent());
}
}
}
} catch (SchemaException ex) {
LOGGER.error("Cannot get refined resource schema for resource {}. {}", resourceModel.getObject().getName().getOrig(), ex.getLocalizedMessage());
}
return availableIntentValues;
}
@Override
public void setObject(List<String> o) {
//
}
@Override
public void detach() {
}
});
intentDropdown.setOutputMarkupId(true);
form.add(intentDropdown);
add(form);
// DropDownChoice kindDropDown = new DropDownChoice<ShadowKindType>(ID_KIND_FIELD, kindModel, Model.ofList(Arrays.asList(ShadowKindType.values()))){
// @Override
// protected void onSelectionChanged(ShadowKindType newSelection) {
// if (newSelection == null){
// ConstructionDetailsPanelChainedModel.this.getModelObject().setKind(null);
// return;
// }
// if (newSelection instanceof ShadowKindType){
// ConstructionDetailsPanelChainedModel.this.getModelObject().setKind((ShadowKindType) newSelection);
// }
// }
// };
// kindDropDown.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
//
// kindDropDown.setOutputMarkupId(true);
// add(kindDropDown);
//
// TextField intentDropDown = new TextField(ID_INTENT_FIELD, intentChoicesModel);
// DropDownChoicePanel intentDropDown = new DropDownChoicePanel(ID_INTENT_FIELD,
// PropertyModel.of(getModel(), ConstructionType.F_INTENT.getLocalPart()), intentChoicesModel);
// intentDropDown.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
// intentDropDown.setOutputMarkupId(true);
// add(intentDropDown);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType in project midpoint by Evolveum.
the class ValueDisplayUtil method toStringValue.
private static String toStringValue(Object value) {
// todo i18n
String defaultStr = "(a value of type " + value.getClass().getSimpleName() + ")";
if (value instanceof String) {
return (String) value;
} else if (value instanceof PolyString) {
return ((PolyString) value).getOrig();
} else if (value instanceof ProtectedStringType) {
// todo i18n
return "(protected string)";
} else if (value instanceof Boolean || value instanceof Integer || value instanceof Long) {
return value.toString();
} else if (value instanceof XMLGregorianCalendar) {
// todo fix
return ((XMLGregorianCalendar) value).toGregorianCalendar().getTime().toLocaleString();
} else if (value instanceof Date) {
// todo fix
return ((Date) value).toLocaleString();
} else if (value instanceof LoginEventType) {
LoginEventType loginEventType = (LoginEventType) value;
if (loginEventType.getTimestamp() != null) {
// todo fix
return loginEventType.getTimestamp().toGregorianCalendar().getTime().toLocaleString();
} else {
return "";
}
} else if (value instanceof ScheduleType) {
return SchemaDebugUtil.prettyPrint((ScheduleType) value);
} else if (value instanceof ApprovalSchemaType) {
ApprovalSchemaType approvalSchemaType = (ApprovalSchemaType) value;
return approvalSchemaType.getName() + (approvalSchemaType.getDescription() != null ? (": " + approvalSchemaType.getDescription()) : "") + " (...)";
} else if (value instanceof ConstructionType) {
ConstructionType ct = (ConstructionType) value;
Object resource = (ct.getResourceRef() != null ? ct.getResourceRef().getOid() : null);
return "resource object" + (resource != null ? " on " + resource : "") + (ct.getDescription() != null ? ": " + ct.getDescription() : "");
} else if (value instanceof Enum) {
return value.toString();
} else if (value instanceof ResourceAttributeDefinitionType) {
ResourceAttributeDefinitionType radt = (ResourceAttributeDefinitionType) value;
ItemPathType ref = radt.getRef();
String path;
if (ref != null) {
path = ref.getItemPath().toString();
} else {
path = "(null)";
}
StringBuilder sb = new StringBuilder();
MappingType mappingType = radt.getOutbound();
if (mappingType != null) {
if (mappingType.getExpression() == null) {
sb.append("Empty mapping for ").append(path);
} else {
sb.append(path).append(" = ");
boolean first = true;
for (JAXBElement<?> evaluator : mappingType.getExpression().getExpressionEvaluator()) {
if (first) {
first = false;
} else {
sb.append(", ");
}
if (QNameUtil.match(SchemaConstants.C_VALUE, evaluator.getName()) && evaluator.getValue() instanceof RawType) {
RawType raw = (RawType) evaluator.getValue();
try {
sb.append(raw.extractString("(a complex value)"));
} catch (RuntimeException e) {
sb.append("(an invalid value)");
}
} else {
sb.append("(a complex expression)");
}
}
}
if (mappingType.getStrength() != null) {
sb.append(" (").append(mappingType.getStrength().value()).append(")");
}
} else {
sb.append("Empty mapping for ").append(path);
}
return sb.toString();
} else if (value instanceof QName) {
QName qname = (QName) value;
return qname.getLocalPart();
// if (StringUtils.isNotEmpty(qname.getNamespaceURI())) {
// return qname.getLocalPart() + " (in " + qname.getNamespaceURI() + ")";
// } else {
// return qname.getLocalPart();
// }
} else if (value instanceof Number) {
return String.valueOf(value);
} else if (value instanceof byte[]) {
return "(binary data)";
} else if (value instanceof RawType) {
try {
Object parsedValue = ((RawType) value).getValue();
return toStringValue(parsedValue);
} catch (SchemaException e) {
return PrettyPrinter.prettyPrint(value);
}
} else if (value instanceof ItemPathType) {
ItemPath itemPath = ((ItemPathType) value).getItemPath();
StringBuilder sb = new StringBuilder();
itemPath.getSegments().forEach(segment -> {
if (ItemPath.isName(segment)) {
sb.append(PrettyPrinter.prettyPrint(ItemPath.toName(segment)));
} else if (ItemPath.isVariable(segment)) {
sb.append(PrettyPrinter.prettyPrint(ItemPath.toVariableName(segment)));
} else {
sb.append(segment.toString());
}
sb.append("; ");
});
return sb.toString();
} else if (value instanceof ExpressionType) {
StringBuilder expressionString = new StringBuilder();
if (((ExpressionType) value).getExpressionEvaluator() != null && ((ExpressionType) value).getExpressionEvaluator().size() > 0) {
((ExpressionType) value).getExpressionEvaluator().forEach(evaluator -> {
if (evaluator.getValue() instanceof RawType) {
expressionString.append(PrettyPrinter.prettyPrint(evaluator.getValue()));
expressionString.append("; ");
} else if (evaluator.getValue() instanceof SearchObjectExpressionEvaluatorType) {
SearchObjectExpressionEvaluatorType evaluatorValue = (SearchObjectExpressionEvaluatorType) evaluator.getValue();
if (evaluatorValue.getFilter() != null) {
DebugUtil.debugDumpMapMultiLine(expressionString, evaluatorValue.getFilter().getFilterClauseXNode().toMap(), 0, false, null);
// TODO temporary hack: removing namespace part of the QName
while (expressionString.indexOf("}") >= 0 && expressionString.indexOf("{") >= 0 && expressionString.indexOf("}") - expressionString.indexOf("{") > 0) {
expressionString.replace(expressionString.indexOf("{"), expressionString.indexOf("}") + 1, "");
}
}
} else {
expressionString.append(defaultStr);
}
});
}
return expressionString.toString();
} else {
return defaultStr;
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType in project midpoint by Evolveum.
the class ConstructionWrapperFactory method createContainerValueWrapper.
@Override
public PrismContainerValueWrapper<ConstructionType> createContainerValueWrapper(PrismContainerWrapper<ConstructionType> objectWrapper, PrismContainerValue<ConstructionType> objectValue, ValueStatus status, WrapperContext context) {
ConstructionValueWrapper constructionValueWrapper = new ConstructionValueWrapper(objectWrapper, objectValue, status);
ConstructionType constructionType = objectValue.asContainerable();
if (constructionType.getResourceRef() != null) {
PrismObject resource = constructionType.getResourceRef().asReferenceValue().getObject();
if (resource != null) {
constructionValueWrapper.setResource(resource);
return constructionValueWrapper;
}
}
setupResource(constructionValueWrapper, constructionType, context);
return constructionValueWrapper;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType in project midpoint by Evolveum.
the class AssignmentTablePanel method addSelectedResourceAssignPerformed.
protected void addSelectedResourceAssignPerformed(ResourceType resource) {
AssignmentType assignment = new AssignmentType();
ConstructionType construction = new ConstructionType();
assignment.setConstruction(construction);
try {
getPageBase().getPrismContext().adopt(assignment, UserType.class, new ItemPath(UserType.F_ASSIGNMENT));
} catch (SchemaException e) {
error(getString("Could not create assignment", resource.getName(), e.getMessage()));
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't create assignment", e);
return;
}
construction.setResource(resource);
List<AssignmentEditorDto> assignments = getAssignmentModel().getObject();
AssignmentEditorDto dto = new AssignmentEditorDto(UserDtoStatus.ADD, assignment, getPageBase());
assignments.add(dto);
dto.setMinimized(true);
dto.setShowEmpty(true);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType in project midpoint by Evolveum.
the class ConsistencyTest method test511AssignAccountMorgan.
/**
* assign account to the user morgan. Account with the same 'uid' (not dn, nut other secondary identifier already exists)
* account should be linked to the user.
* @throws Exception
*/
@Test
public void test511AssignAccountMorgan() throws Exception {
final String TEST_NAME = "test511AssignAccountMorgan";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
openDJController.assumeRunning();
Task task = taskManager.createTaskInstance(ConsistencyTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
//prepare new OU in opendj
Entry entry = openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILENAME);
PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
display("User Morgan: ", user);
PrismReference linkRef = user.findReference(UserType.F_LINK_REF);
ExpressionType expression = new ExpressionType();
ObjectFactory of = new ObjectFactory();
RawType raw = new RawType(new PrimitiveXNode("uid=morgan,ou=users,dc=example,dc=com"), prismContext);
JAXBElement val = of.createValue(raw);
expression.getExpressionEvaluator().add(val);
MappingType mapping = new MappingType();
mapping.setExpression(expression);
ResourceAttributeDefinitionType attrDefType = new ResourceAttributeDefinitionType();
attrDefType.setRef(new ItemPathType(new ItemPath(getOpenDjSecondaryIdentifierQName())));
attrDefType.setOutbound(mapping);
ConstructionType construction = new ConstructionType();
construction.getAttribute().add(attrDefType);
construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo));
AssignmentType assignment = new AssignmentType();
assignment.setConstruction(construction);
ObjectDelta<UserType> userDelta = ObjectDelta.createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, prismContext, assignment.asPrismContainerValue());
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
// assertEquals("Expected handled error but got: " + result.getStatus(), OperationResultStatus.HANDLED_ERROR, result.getStatus());
PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
display("User morgan after", userMorgan);
UserType userMorganType = userMorgan.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userMorganType.getLinkRef().size());
String accountOid = userMorganType.getLinkRef().iterator().next().getOid();
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertShadowModel(accountModel, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
ResourceAttribute attributes = ShadowUtil.getAttribute(accountModel, new QName(resourceTypeOpenDjrepo.getNamespace(), "uid"));
assertEquals("morgan", attributes.getAnyRealValue());
// TODO: check OpenDJ Account
}
Aggregations