use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class PageResources method initLayout.
private void initLayout() {
Form mainForm = new Form(ID_MAIN_FORM);
add(mainForm);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
options.add(SelectorOptions.create(ResourceType.F_CONNECTOR_REF, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE)));
MainObjectListPanel<ResourceType> resourceListPanel = new MainObjectListPanel<ResourceType>(ID_TABLE, ResourceType.class, TableId.TABLE_RESOURCES, options, this) {
private static final long serialVersionUID = 1L;
@Override
protected List<InlineMenuItem> createInlineMenu() {
return PageResources.this.createRowMenuItems(false);
}
@Override
protected List<IColumn<SelectableBean<ResourceType>, String>> createColumns() {
return PageResources.this.initResourceColumns();
}
@Override
protected IColumn<SelectableBean<ResourceType>, String> createActionsColumn() {
return PageResources.this.createResourceActionsColumn();
}
@Override
protected void objectDetailsPerformed(AjaxRequestTarget target, ResourceType object) {
PageResources.this.resourceDetailsPerformed(target, object.getOid());
}
@Override
protected void newObjectPerformed(AjaxRequestTarget target) {
navigateToNext(PageResourceWizard.class);
}
};
resourceListPanel.setOutputMarkupId(true);
resourceListPanel.setAdditionalBoxCssClasses(GuiStyleConstants.CLASS_OBJECT_RESOURCE_BOX_CSS_CLASSES);
mainForm.add(resourceListPanel);
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class PageResource method loadResource.
private PrismObject<ResourceType> loadResource() {
String resourceOid = getResourceOid();
LOGGER.trace("Loading resource with oid: {}", resourceOid);
Task task = createSimpleTask(OPERATION_LOAD_RESOURCE);
OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCE);
Collection<SelectorOptions<GetOperationOptions>> resolveConnectorOption = SelectorOptions.createCollection(ResourceType.F_CONNECTOR, GetOperationOptions.createResolve());
resolveConnectorOption.add(SelectorOptions.create(GetOperationOptions.createNoFetch()));
PrismObject<ResourceType> resource = WebModelServiceUtils.loadObject(ResourceType.class, resourceOid, resolveConnectorOption, this, task, result);
result.recomputeStatus();
showResult(result, "pageAdminResources.message.cantLoadResource", false);
return resource;
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class PrismValuePanel method createTypedInputComponent.
// normally this method returns an InputPanel;
// however, for some special readonly types (like ObjectDeltaType) it will return a Panel
private Panel createTypedInputComponent(String id) {
// ValueWrapper valueWrapper = model.getObject();
// ItemWrapper itemWrapper =
final Item item = valueWrapperModel.getObject().getItem().getItem();
Panel panel = null;
if (item instanceof PrismProperty) {
final PrismProperty property = (PrismProperty) item;
PrismPropertyDefinition definition = property.getDefinition();
final QName valueType = definition.getTypeName();
//pointing to prism property real value
final String baseExpression = "value.value";
//now it works only in description
if (ObjectType.F_DESCRIPTION.equals(definition.getName())) {
return new TextAreaPanel(id, new PropertyModel(valueWrapperModel, baseExpression), null);
}
if (ActivationType.F_ADMINISTRATIVE_STATUS.equals(definition.getName())) {
return WebComponentUtil.createEnumPanel(ActivationStatusType.class, id, new PropertyModel<ActivationStatusType>(valueWrapperModel, baseExpression), this);
} else if (ActivationType.F_LOCKOUT_STATUS.equals(definition.getName())) {
return new LockoutStatusPanel(id, valueWrapperModel.getObject(), new PropertyModel<LockoutStatusType>(valueWrapperModel, baseExpression));
} else {
if (definition.getTypeName().getLocalPart().equals(ActivationStatusType.class.getSimpleName())) {
return WebComponentUtil.createEnumPanel(ActivationStatusType.class, id, new PropertyModel<ActivationStatusType>(valueWrapperModel, baseExpression), this);
}
}
if (DOMUtil.XSD_DATETIME.equals(valueType)) {
panel = new DatePanel(id, new PropertyModel<XMLGregorianCalendar>(valueWrapperModel, baseExpression));
} else if (ProtectedStringType.COMPLEX_TYPE.equals(valueType)) {
panel = new PasswordPanel(id, new PropertyModel<ProtectedStringType>(valueWrapperModel, baseExpression), valueWrapperModel.getObject().isReadonly());
} else if (DOMUtil.XSD_BOOLEAN.equals(valueType)) {
panel = new TriStateComboPanel(id, new PropertyModel<Boolean>(valueWrapperModel, baseExpression));
} else if (SchemaConstants.T_POLY_STRING_TYPE.equals(valueType)) {
InputPanel inputPanel;
PrismPropertyDefinition def = property.getDefinition();
if (def.getValueEnumerationRef() != null) {
PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
String lookupTableUid = valueEnumerationRef.getOid();
Task task = pageBase.createSimpleTask("loadLookupTable");
OperationResult result = task.getResult();
Collection<SelectorOptions<GetOperationOptions>> options = WebModelServiceUtils.createLookupTableRetrieveOptions();
final PrismObject<LookupTableType> lookupTable = WebModelServiceUtils.loadObject(LookupTableType.class, lookupTableUid, options, pageBase, task, result);
if (lookupTable != null) {
inputPanel = new AutoCompleteTextPanel<String>(id, new LookupPropertyModel<String>(valueWrapperModel, baseExpression + ".orig", lookupTable.asObjectable()), String.class) {
@Override
public Iterator<String> getIterator(String input) {
return prepareAutoCompleteList(input, lookupTable).iterator();
}
};
} else {
inputPanel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression + ".orig"), String.class);
}
} else {
inputPanel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression + ".orig"), String.class);
}
if (ObjectType.F_NAME.equals(def.getName()) || UserType.F_FULL_NAME.equals(def.getName())) {
inputPanel.getBaseFormComponent().setRequired(true);
}
panel = inputPanel;
} else if (DOMUtil.XSD_BASE64BINARY.equals(valueType)) {
panel = new UploadDownloadPanel(id, valueWrapperModel.getObject().isReadonly()) {
@Override
public InputStream getStream() {
Object object = ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).getValue();
return object != null ? new ByteArrayInputStream((byte[]) object) : new ByteArrayInputStream(new byte[0]);
// return super.getStream();
}
@Override
public void updateValue(byte[] file) {
((PrismPropertyValue) valueWrapperModel.getObject().getValue()).setValue(file);
}
@Override
public void uploadFilePerformed(AjaxRequestTarget target) {
super.uploadFilePerformed(target);
target.add(PrismValuePanel.this.get(ID_FEEDBACK));
}
@Override
public void removeFilePerformed(AjaxRequestTarget target) {
super.removeFilePerformed(target);
target.add(PrismValuePanel.this.get(ID_FEEDBACK));
}
@Override
public void uploadFileFailed(AjaxRequestTarget target) {
super.uploadFileFailed(target);
target.add(PrismValuePanel.this.get(ID_FEEDBACK));
target.add(((PageBase) getPage()).getFeedbackPanel());
}
};
} else if (ObjectDeltaType.COMPLEX_TYPE.equals(valueType)) {
panel = new ModificationsPanel(id, new AbstractReadOnlyModel<DeltaDto>() {
@Override
public DeltaDto getObject() {
if (valueWrapperModel.getObject() == null || valueWrapperModel.getObject().getValue() == null || ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).getValue() == null) {
return null;
}
PrismContext prismContext = ((PageBase) getPage()).getPrismContext();
ObjectDeltaType objectDeltaType = (ObjectDeltaType) ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).getValue();
try {
ObjectDelta delta = DeltaConvertor.createObjectDelta(objectDeltaType, prismContext);
return new DeltaDto(delta);
} catch (SchemaException e) {
throw new IllegalStateException("Couldn't convert object delta: " + objectDeltaType);
}
}
});
} else if (QueryType.COMPLEX_TYPE.equals(valueType) || CleanupPoliciesType.COMPLEX_TYPE.equals(valueType)) {
return new TextAreaPanel(id, new AbstractReadOnlyModel() {
@Override
public Object getObject() {
if (valueWrapperModel.getObject() == null || valueWrapperModel.getObject().getValue() == null) {
return null;
}
PrismPropertyValue ppv = (PrismPropertyValue) valueWrapperModel.getObject().getValue();
if (ppv == null || ppv.getValue() == null) {
return null;
}
QName name = property.getElementName();
if (name == null && property.getDefinition() != null) {
name = property.getDefinition().getName();
}
if (name == null) {
name = SchemaConstants.C_VALUE;
}
PrismContext prismContext = ((PageBase) getPage()).getPrismContext();
try {
return prismContext.xmlSerializer().serializeAnyData(ppv.getValue(), name);
} catch (SchemaException e) {
throw new SystemException("Couldn't serialize property value of type: " + valueType + ": " + e.getMessage(), e);
}
}
}, 10);
} else {
Class type = XsdTypeMapper.getXsdToJavaMapping(valueType);
if (type != null && type.isPrimitive()) {
type = ClassUtils.primitiveToWrapper(type);
}
if (isEnum(property)) {
return WebComponentUtil.createEnumPanel(definition, id, new PropertyModel<>(valueWrapperModel, baseExpression), this);
}
// // default QName validation is a bit weird, so let's treat QNames as strings [TODO finish this - at the parsing side]
// if (type == QName.class) {
// type = String.class;
// }
PrismPropertyDefinition def = property.getDefinition();
if (def.getValueEnumerationRef() != null) {
PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
String lookupTableUid = valueEnumerationRef.getOid();
Task task = pageBase.createSimpleTask("loadLookupTable");
OperationResult result = task.getResult();
Collection<SelectorOptions<GetOperationOptions>> options = WebModelServiceUtils.createLookupTableRetrieveOptions();
final PrismObject<LookupTableType> lookupTable = WebModelServiceUtils.loadObject(LookupTableType.class, lookupTableUid, options, pageBase, task, result);
if (lookupTable != null) {
panel = new AutoCompleteTextPanel<String>(id, new LookupPropertyModel<String>(valueWrapperModel, baseExpression, lookupTable == null ? null : lookupTable.asObjectable()), type) {
@Override
public Iterator<String> getIterator(String input) {
return prepareAutoCompleteList(input, lookupTable).iterator();
}
@Override
public void checkInputValue(AutoCompleteTextField input, AjaxRequestTarget target, LookupPropertyModel model) {
Iterator<String> lookupTableValuesIterator = prepareAutoCompleteList("", lookupTable).iterator();
String value = input.getInput();
boolean isValueExist = false;
if (value != null) {
if (value.trim().equals("")) {
isValueExist = true;
} else {
while (lookupTableValuesIterator.hasNext()) {
String lookupTableValue = lookupTableValuesIterator.next();
if (value.trim().equals(lookupTableValue)) {
isValueExist = true;
break;
}
}
}
}
if (isValueExist) {
input.setModelValue(new String[] { value });
target.add(PrismValuePanel.this.get(ID_FEEDBACK));
} else {
input.error("Entered value doesn't match any of available values and will not be saved.");
target.add(PrismValuePanel.this.get(ID_FEEDBACK));
}
}
};
} else {
panel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression), type);
}
} else {
panel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression), type);
}
}
} else if (item instanceof PrismReference) {
PrismContext prismContext = item.getPrismContext();
if (prismContext == null) {
prismContext = pageBase.getPrismContext();
}
QName targetTypeName = ((PrismReferenceDefinition) item.getDefinition()).getTargetTypeName();
Class targetClass = null;
if (targetTypeName != null && prismContext != null) {
targetClass = prismContext.getSchemaRegistry().determineCompileTimeClass(targetTypeName);
}
final Class typeClass = targetClass != null ? targetClass : (item.getDefinition().getTypeClassIfKnown() != null ? item.getDefinition().getTypeClassIfKnown() : FocusType.class);
Collection typeClasses = new ArrayList();
// HACK HACK MID-3201 MID-3231
if (isUserOrgItem(item, typeClass)) {
typeClasses.add(UserType.class);
typeClasses.add(OrgType.class);
} else {
typeClasses.add(typeClass);
}
panel = new ValueChoosePanel(id, new PropertyModel<>(valueWrapperModel, "value"), item.getValues(), false, typeClasses);
} else if (item instanceof PrismContainer<?>) {
AssociationWrapper itemWrapper = (AssociationWrapper) valueWrapperModel.getObject().getItem();
final PrismContainer container = (PrismContainer) item;
PrismContainerDefinition definition = container.getDefinition();
QName valueType = definition.getTypeName();
if (ShadowAssociationType.COMPLEX_TYPE.equals(valueType)) {
PrismContext prismContext = item.getPrismContext();
if (prismContext == null) {
prismContext = pageBase.getPrismContext();
}
ShadowType shadowType = ((ShadowType) itemWrapper.getContainer().getObject().getObject().asObjectable());
PrismObject<ResourceType> resource = shadowType.getResource().asPrismObject();
// of resources.
try {
resource.revive(prismContext);
} catch (SchemaException e) {
throw new SystemException(e.getMessage(), e);
}
RefinedResourceSchema refinedSchema;
CompositeRefinedObjectClassDefinition rOcDef;
try {
refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
rOcDef = refinedSchema.determineCompositeObjectClassDefinition(shadowType.asPrismObject());
} catch (SchemaException e) {
throw new SystemException(e.getMessage(), e);
}
RefinedAssociationDefinition assocDef = itemWrapper.getRefinedAssociationDefinition();
RefinedObjectClassDefinition assocTargetDef = assocDef.getAssociationTarget();
ObjectQuery query = getAssociationsSearchQuery(prismContext, resource, assocTargetDef.getTypeName(), assocTargetDef.getKind());
List values = item.getValues();
return new AssociationValueChoicePanel(id, valueWrapperModel, values, false, ShadowType.class, query, assocTargetDef);
}
}
return panel;
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class PageAccounts method createTotalsModel.
private LoadableModel<Integer> createTotalsModel(final SynchronizationSituationType situation) {
return new LoadableModel<Integer>(false) {
@Override
protected Integer load() {
ObjectFilter resourceFilter = createResourceQueryFilter();
if (resourceFilter == null) {
return 0;
}
ObjectFilter filter = createObjectQuery().getFilter();
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
Task task = createSimpleTask(OPERATION_GET_TOTALS);
OperationResult result = new OperationResult(OPERATION_GET_TOTALS);
try {
ObjectFilter situationFilter = QueryBuilder.queryFor(ShadowType.class, getPrismContext()).item(ShadowType.F_SYNCHRONIZATION_SITUATION).eq(situation).buildFilter();
ObjectQuery query = ObjectQuery.createObjectQuery(AndFilter.createAnd(filter, situationFilter));
return getModelService().countObjects(ShadowType.class, query, options, task, result);
} catch (CommonException | RuntimeException ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't count shadows", ex);
}
return 0;
}
};
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class PageSystemConfiguration method loadSystemConfiguration.
private SystemConfigurationDto loadSystemConfiguration() {
Task task = createSimpleTask(TASK_GET_SYSTEM_CONFIG);
OperationResult result = new OperationResult(TASK_GET_SYSTEM_CONFIG);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createResolve(), SystemConfigurationType.F_DEFAULT_USER_TEMPLATE, SystemConfigurationType.F_GLOBAL_PASSWORD_POLICY);
SystemConfigurationDto dto = null;
try {
PrismObject<SystemConfigurationType> systemConfig = WebModelServiceUtils.loadObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), options, this, task, result);
dto = new SystemConfigurationDto(systemConfig);
result.recordSuccess();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load system configuration", ex);
result.recordFatalError("Couldn't load system configuration.", ex);
}
// null :)
if (!WebComponentUtil.isSuccessOrHandledError(result) || dto == null) {
showResult(result, false);
throw getRestartResponseException(PageError.class);
}
return dto;
}
Aggregations