use of com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition in project midpoint by Evolveum.
the class CapabilityStep method editCapabilityPerformed.
@SuppressWarnings("unchecked")
private void editCapabilityPerformed(final AjaxRequestTarget target, CapabilityDto<? extends CapabilityType> capability) {
dtoModel.getObject().setSelected(capability);
WebMarkupContainer config = getConfigContainer();
WebMarkupContainer newConfig;
CapabilityType capType = capability.getCapability();
if (capType instanceof ActivationCapabilityType) {
newConfig = new CapabilityActivationPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<ActivationCapabilityType>) capability), parentPage) {
@Override
public IModel<List<QName>> createAttributeChoiceModel(final IChoiceRenderer<QName> renderer) {
LoadableModel<List<QName>> attributeChoiceModel = new LoadableModel<List<QName>>(false) {
@Override
protected List<QName> load() {
List<QName> choices = new ArrayList<>();
PrismObject<ResourceType> resourcePrism = resourceModel.getObject();
try {
ResourceSchema schema = ResourceSchemaFactory.getCompleteSchema(resourcePrism);
if (schema != null) {
// TODO is this OK?
ResourceObjectTypeDefinition def = schema.findDefaultOrAnyObjectTypeDefinition(ShadowKindType.ACCOUNT);
if (def != null) {
for (ResourceAttributeDefinition<?> attribute : def.getAttributeDefinitions()) {
choices.add(attribute.getItemName());
}
}
}
} catch (CommonException | RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load resource schema attributes.", e);
getPageBase().error("Couldn't load resource schema attributes" + e);
}
choices.sort((o1, o2) -> {
String s1 = (String) renderer.getDisplayValue(o1);
String s2 = (String) renderer.getDisplayValue(o2);
return String.CASE_INSENSITIVE_ORDER.compare(s1, s2);
});
return choices;
}
};
parentPage.registerDependentModel(attributeChoiceModel);
return attributeChoiceModel;
}
};
} else if (capType instanceof ScriptCapabilityType) {
newConfig = new CapabilityScriptPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<ScriptCapabilityType>) capability), getTable(), parentPage);
} else if (capType instanceof CredentialsCapabilityType) {
newConfig = new CapabilityCredentialsPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<CredentialsCapabilityType>) capability), getTable(), parentPage);
} else {
newConfig = new CapabilityValuePanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<CapabilityType>) capability), getTable(), parentPage);
}
// TODO other specific capabilities (paged, count, ...)
newConfig.setOutputMarkupId(true);
config.replaceWith(newConfig);
target.add(newConfig);
target.add(getTable());
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition in project midpoint by Evolveum.
the class FocusProjectionsPanel method addSelectedAccountPerformed.
private void addSelectedAccountPerformed(AjaxRequestTarget target, List<ResourceType> newResources) {
getPageBase().hideMainPopup(target);
if (newResources.isEmpty()) {
warn(getString("pageUser.message.noResourceSelected"));
return;
}
for (ResourceType resource : newResources) {
try {
ResourceSchema refinedSchema = getRefinedSchema(resource);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Refined schema for {}\n{}", resource, refinedSchema.debugDump());
}
ResourceObjectTypeDefinition accountDefinition = refinedSchema.findDefaultOrAnyObjectTypeDefinition(ShadowKindType.ACCOUNT);
if (accountDefinition == null) {
error(getString("pageAdminFocus.message.couldntCreateAccountNoAccountSchema", resource.getName()));
continue;
}
// shadow.asPrismContainer().findOrCreateContainer(ShadowType.F_ATTRIBUTES).applyDefinition(accountDefinition.toResourceAttributeContainerDefinition());
ShadowType shadow = createNewShadow(resource, accountDefinition);
ShadowWrapper wrapperNew = createShadowWrapper(shadow);
getProjectionsModel().getObject().add(wrapperNew);
} catch (Exception ex) {
error(getString("pageAdminFocus.message.couldntCreateAccount", resource.getName(), ex.getMessage()));
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't create account", ex);
}
}
target.add(getMultivalueContainerListPanel());
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition in project midpoint by Evolveum.
the class TypedAssignablePanel method getIntentAvailableValuesModel.
private LoadableModel<List<String>> getIntentAvailableValuesModel() {
return new LoadableModel<>(true) {
private static final long serialVersionUID = 1L;
@Override
protected List<String> load() {
List<String> availableIntentValues = new ArrayList<>();
if (getResourceTable() != null) {
List<T> selectedResources = getResourceTable().getSelectedRealObjects();
if (selectedResources != null && selectedResources.size() > 0) {
ResourceType selectedResource = (ResourceType) selectedResources.get(0);
try {
ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(selectedResource.asPrismObject());
if (refinedSchema != null) {
ShadowKindType kind = (ShadowKindType) TypedAssignablePanel.this.getKindDropdownComponent().getBaseFormComponent().getModelObject();
List<? extends ResourceObjectTypeDefinition> definitions = refinedSchema.getObjectTypeDefinitions(kind);
for (ResourceObjectTypeDefinition def : definitions) {
availableIntentValues.add(def.getIntent());
}
}
} catch (SchemaException ex) {
LOGGER.error("Cannot get refined resource schema for resource {}. {}", selectedResource.getName().getOrig(), ex.getLocalizedMessage());
}
}
}
return availableIntentValues;
}
};
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition in project midpoint by Evolveum.
the class SynchronizationUtils method isPolicyApplicable.
/**
* Checks if the synchronization policy matches given "parameters" (object class, kind, intent).
*/
public static boolean isPolicyApplicable(QName objectClass, ShadowKindType kind, String intent, @NotNull ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource, boolean strictIntent) throws SchemaException {
if (objectClassDefinedAndNotMatching(objectClass, synchronizationPolicy.getObjectClass())) {
return false;
}
ResourceSchema schema = ResourceSchemaFactory.getCompleteSchema(resource);
Objects.requireNonNull(schema, "No schema defined in resource. Possible configuration problem?");
ShadowKindType policyKind = requireNonNullElse(synchronizationPolicy.getKind(), ACCOUNT);
String policyIntent = synchronizationPolicy.getIntent();
ResourceObjectDefinition policyObjectClass;
if (StringUtils.isEmpty(policyIntent)) {
// TODO check this
policyObjectClass = schema.findObjectDefinition(policyKind, null);
if (policyObjectClass instanceof ResourceObjectTypeDefinition) {
policyIntent = ((ResourceObjectTypeDefinition) policyObjectClass).getIntent();
}
} else {
policyObjectClass = schema.findObjectDefinition(policyKind, policyIntent);
}
if (policyObjectClass == null) {
return false;
}
// re-check objectClass if wasn't defined
if (objectClassDefinedAndNotMatching(objectClass, List.of(policyObjectClass.getTypeName()))) {
return false;
}
// kind
LOGGER.trace("Comparing kinds, policy kind: {}, current kind: {}", policyKind, kind);
if (kind != null && kind != UNKNOWN && !policyKind.equals(kind)) {
LOGGER.trace("Kinds don't match, skipping policy {}", synchronizationPolicy);
return false;
}
// intent
// TODO is the intent always present in shadow at this time? [med]
LOGGER.trace("Comparing intents, policy intent: {}, current intent: {}", policyIntent, intent);
if (!strictIntent) {
if (intent != null && !SchemaConstants.INTENT_UNKNOWN.equals(intent) && !MiscSchemaUtil.equalsIntent(intent, policyIntent)) {
LOGGER.trace("Intents don't match, skipping policy {}", synchronizationPolicy);
return false;
}
} else {
if (!MiscSchemaUtil.equalsIntent(intent, policyIntent)) {
LOGGER.trace("Intents don't match, skipping policy {}", synchronizationPolicy);
return false;
}
}
return true;
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition in project midpoint by Evolveum.
the class SchemaListPanel method loadAllClasses.
private List<ObjectClassDto> loadAllClasses() {
List<ObjectClassDto> list = new ArrayList<>();
ResourceSchema schema = loadResourceSchema();
if (schema == null) {
return list;
}
for (ResourceObjectTypeDefinition definition : schema.getObjectTypeDefinitions()) {
list.add(new ObjectClassDto(definition));
}
Collections.sort(list);
return list;
}
Aggregations