use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class AbstractTreeTablePanel method createOrgChildQuery.
protected ObjectQuery createOrgChildQuery() {
SelectableBean<OrgType> dto = selected.getObject();
String oid = dto != null && dto.getValue() != null ? dto.getValue().getOid() : getModel().getObject();
BasicSearchPanel<String> basicSearch = (BasicSearchPanel) get(createComponentPath(ID_SEARCH_FORM, ID_BASIC_SEARCH));
String object = basicSearch.getModelObject();
DropDownChoice<String> searchScopeChoice = (DropDownChoice) get(createComponentPath(ID_SEARCH_FORM, ID_SEARCH_SCOPE));
String scope = searchScopeChoice.getModelObject();
if (StringUtils.isBlank(object)) {
object = null;
}
PageBase page = getPageBase();
PrismContext context = page.getPrismContext();
S_AtomicFilterExit q;
if (object == null || SEARCH_SCOPE_ONE.equals(scope)) {
q = QueryBuilder.queryFor(OrgType.class, context).isDirectChildOf(oid);
} else {
q = QueryBuilder.queryFor(OrgType.class, context).isChildOf(oid);
}
if (object == null) {
return q.build();
}
PolyStringNormalizer normalizer = context.getDefaultPolyStringNormalizer();
String normalizedString = normalizer.normalize(object);
if (StringUtils.isEmpty(normalizedString)) {
return q.build();
}
ObjectQuery query = q.and().block().item(OrgType.F_NAME).containsPoly(normalizedString).matchingNorm().or().item(OrgType.F_DISPLAY_NAME).containsPoly(normalizedString).matchingNorm().build();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Searching child orgs of org {} with query:\n{}", oid, query.debugDump());
}
return query;
}
use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class TreeTablePanel method initObjectForAdd.
// TODO: merge this with AbstractRoleMemeberPanel.initObjectForAdd, also see MID-3233
private void initObjectForAdd(ObjectReferenceType parentOrgRef, QName type, QName relation, AjaxRequestTarget target) throws SchemaException {
TreeTablePanel.this.getPageBase().hideMainPopup(target);
PrismContext prismContext = TreeTablePanel.this.getPageBase().getPrismContext();
PrismObjectDefinition def = prismContext.getSchemaRegistry().findObjectDefinitionByType(type);
PrismObject obj = def.instantiate();
ObjectType objType = (ObjectType) obj.asObjectable();
if (FocusType.class.isAssignableFrom(obj.getCompileTimeClass())) {
AssignmentType assignment = new AssignmentType();
assignment.setTargetRef(parentOrgRef);
((FocusType) objType).getAssignment().add(assignment);
}
// TODO: fix MID-3234
if (parentOrgRef == null) {
ObjectType org = getTreePanel().getSelected().getValue();
parentOrgRef = ObjectTypeUtil.createObjectRef(org);
parentOrgRef.setRelation(relation);
objType.getParentOrgRef().add(parentOrgRef);
} else {
objType.getParentOrgRef().add(parentOrgRef.clone());
}
WebComponentUtil.dispatchToObjectDetailsPage(obj, this);
}
use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class NameStep method applyState.
@Override
public void applyState() {
parentPage.refreshIssues(null);
if (parentPage.isReadOnly() || !isComplete()) {
return;
}
PrismContext prismContext = parentPage.getPrismContext();
Task task = parentPage.createSimpleTask(OPERATION_SAVE_RESOURCE);
OperationResult result = task.getResult();
boolean saved = false;
try {
PrismObject<ResourceType> resource = resourceModelRaw.getObject();
PrismObject<ConnectorType> connector = getSelectedConnector();
if (connector == null) {
// should be treated by form validation
throw new IllegalStateException("No connector selected");
}
ObjectDelta delta;
final String oid = resource.getOid();
boolean isNew = oid == null;
if (isNew) {
resource = prismContext.createObject(ResourceType.class);
ResourceType resourceType = resource.asObjectable();
resourceType.setName(PolyStringType.fromOrig(resourceNameModel.getObject()));
resourceType.setDescription(resourceDescriptionModel.getObject());
resourceType.setConnectorRef(ObjectTypeUtil.createObjectRef(connector));
delta = ObjectDelta.createAddDelta(resource);
} else {
PrismObject<ResourceType> oldResourceObject = WebModelServiceUtils.loadObject(ResourceType.class, oid, GetOperationOptions.createRawCollection(), parentPage, parentPage.createSimpleTask("loadResource"), result);
if (oldResourceObject == null) {
throw new SystemException("Resource being edited (" + oid + ") couldn't be retrieved");
}
ResourceType oldResource = oldResourceObject.asObjectable();
S_ItemEntry i = DeltaBuilder.deltaFor(ResourceType.class, prismContext);
if (!StringUtils.equals(PolyString.getOrig(oldResource.getName()), resourceNameModel.getObject())) {
i = i.item(ResourceType.F_NAME).replace(PolyString.fromOrig(resourceNameModel.getObject()));
}
if (!StringUtils.equals(oldResource.getDescription(), resourceDescriptionModel.getObject())) {
i = i.item(ResourceType.F_DESCRIPTION).replace(resourceDescriptionModel.getObject());
}
String oldConnectorOid = oldResource.getConnectorRef() != null ? oldResource.getConnectorRef().getOid() : null;
String newConnectorOid = connector.getOid();
if (!StringUtils.equals(oldConnectorOid, newConnectorOid)) {
i = i.item(ResourceType.F_CONNECTOR_REF).replace(ObjectTypeUtil.createObjectRef(connector).asReferenceValue());
}
if (!isConfigurationSchemaCompatible(connector)) {
i = i.item(ResourceType.F_CONNECTOR_CONFIGURATION).replace();
}
delta = i.asObjectDelta(oid);
}
if (!delta.isEmpty()) {
parentPage.logDelta(delta);
WebModelServiceUtils.save(delta, ModelExecuteOptions.createRaw(), result, null, parentPage);
parentPage.resetModels();
saved = true;
}
if (isNew) {
parentPage.setEditedResourceOid(delta.getOid());
}
} catch (RuntimeException | SchemaException ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save resource", ex);
result.recordFatalError("Couldn't save resource, reason: " + ex.getMessage(), ex);
} finally {
result.computeStatusIfUnknown();
setResult(result);
}
if (parentPage.showSaveResultInPage(saved, result)) {
parentPage.showResult(result);
}
}
use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class PageDebugView method initViewButton.
private void initViewButton(Form mainForm) {
List<String> propertyKeysList = Arrays.asList("PageDebugView.xmlViewButton", "PageDebugView.xmlJsonButton", "PageDebugView.xmlYamlButton");
int selectedIndex = 0;
if (PrismContext.LANG_JSON.equals(dataLanguage)) {
selectedIndex = 1;
} else if (PrismContext.LANG_YAML.equals(dataLanguage)) {
selectedIndex = 2;
}
MultiStateHorizontalButton viewButtonPanel = new MultiStateHorizontalButton(ID_VIEW_BUTTON_PANEL, selectedIndex, propertyKeysList, PageDebugView.this) {
@Override
protected void onStateChanged(int index, AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_VALIDATE_OBJECT);
Holder<PrismObject<ObjectType>> objectHolder = new Holder<>(null);
try {
validateObject(result, objectHolder);
if (result.isAcceptable()) {
if (index == 1) {
dataLanguage = PrismContext.LANG_JSON;
} else if (index == 2) {
dataLanguage = PrismContext.LANG_YAML;
} else {
dataLanguage = PrismContext.LANG_XML;
}
PrismObject<ObjectType> updatedObject = objectHolder.getValue();
PrismContext context = getMidpointApplication().getPrismContext();
String objectStr = context.serializerFor(dataLanguage).serialize(updatedObject);
objectViewDto.setXml(objectStr);
setSelectedIndex(index);
addOrReplaceEditor();
target.add(mainForm);
target.add(getFeedbackPanel());
} else {
showResult(result);
target.add(getFeedbackPanel());
}
} catch (Exception ex) {
result.recordFatalError("Couldn't change the language.", ex);
showResult(result);
target.add(getFeedbackPanel());
}
}
};
viewButtonPanel.setOutputMarkupId(true);
mainForm.add(viewButtonPanel);
}
use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class ExecuteChangesHandlerDto method getOptions.
public String getOptions() {
ModelExecuteOptionsType options = taskDto.getExtensionPropertyRealValue(SchemaConstants.MODEL_EXTENSION_EXECUTE_OPTIONS, ModelExecuteOptionsType.class);
if (options == null) {
return null;
}
PrismContext prismContext = MidPointApplication.get().getPrismContext();
try {
return WebXmlUtil.stripNamespaceDeclarations(prismContext.xmlSerializer().serializeAnyData(options, SchemaConstants.MODEL_EXTENSION_EXECUTE_OPTIONS));
} catch (SchemaException e) {
throw new SystemException("Couldn't serialize model execute options: " + e.getMessage(), e);
}
}
Aggregations