use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ResourceDetailsTabPanel method getTaskFor.
private List<TaskType> getTaskFor(List<PrismObject<TaskType>> tasks, ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException {
List<TaskType> syncTasks = new ArrayList<>();
for (PrismObject<TaskType> task : tasks) {
ShadowKindType taskKindValue = null;
String taskIntentValue = null;
QName taskObjectClassValue = null;
@Nullable ResourceObjectSetType resourceSet = ResourceObjectSetUtil.fromTask(task.asObjectable());
if (!Objects.isNull(resourceSet)) {
taskKindValue = resourceSet.getKind();
taskIntentValue = resourceSet.getIntent();
taskObjectClassValue = resourceSet.getObjectclass();
}
// is not accessible in admin-gui)
if (taskObjectClassValue == null) {
ResourceObjectDefinition taskObjectClassDef = null;
ResourceSchema schema = ResourceSchemaFactory.getCompleteSchema(resource);
if (schema == null) {
throw new SchemaException("No schema defined in resource. Possible configuration problem?");
}
if (taskKindValue == null && taskIntentValue == null) {
// TODO ok?
taskObjectClassDef = schema.findObjectDefinition(ShadowKindType.ACCOUNT, null);
}
if (taskKindValue != null) {
if (StringUtils.isEmpty(taskIntentValue)) {
// TODO ok?
taskObjectClassDef = schema.findObjectDefinition(taskKindValue, null);
} else {
taskObjectClassDef = schema.findObjectDefinition(taskKindValue, taskIntentValue);
}
}
if (taskObjectClassDef != null) {
taskObjectClassValue = taskObjectClassDef.getTypeName();
}
}
if (SynchronizationUtils.isPolicyApplicable(taskObjectClassValue, taskKindValue, taskIntentValue, synchronizationPolicy, resource, true)) {
syncTasks.add(task.asObjectable());
}
}
return syncTasks;
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ResourceContentTabPanel method initLayout.
private void initLayout() {
setOutputMarkupId(true);
final Form mainForm = new MidpointForm(ID_MAIN_FORM);
mainForm.setOutputMarkupId(true);
mainForm.addOrReplace(initTable(getModel()));
add(mainForm);
AutoCompleteTextPanel<String> intent = new AutoCompleteTextPanel<String>(ID_INTENT, new PropertyModel<>(resourceContentSearch, "intent"), String.class, false, null) {
private static final long serialVersionUID = 1L;
@Override
public Iterator<String> getIterator(String input) {
ResourceSchema refinedSchema;
try {
refinedSchema = ResourceSchemaFactory.getCompleteSchema(getModelObject());
if (refinedSchema != null) {
return refinedSchema.getIntentsForKind(getKind()).iterator();
} else {
return Collections.emptyIterator();
}
} catch (SchemaException e) {
return Collections.emptyIterator();
}
}
};
intent.getBaseFormComponent().add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(get(ID_REAL_OBJECT_CLASS));
updateResourceContentSearch();
mainForm.addOrReplace(initTable(getModel()));
target.add(mainForm);
}
});
intent.setOutputMarkupId(true);
intent.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return !isUseObjectClass();
}
});
add(intent);
Label realObjectClassLabel = new Label(ID_REAL_OBJECT_CLASS, new IModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
ResourceObjectDefinition ocDef;
try {
ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(getModelObject());
if (refinedSchema == null) {
return "NO SCHEMA DEFINED";
}
ocDef = refinedSchema.findObjectDefinition(getKind(), getIntent());
if (ocDef != null) {
return ocDef.getObjectClassDefinition().getTypeName().getLocalPart();
}
} catch (SchemaException e) {
}
return "NOT FOUND";
}
});
realObjectClassLabel.setOutputMarkupId(true);
add(realObjectClassLabel);
AutoCompleteQNamePanel objectClassPanel = new AutoCompleteQNamePanel(ID_OBJECT_CLASS, new PropertyModel<>(resourceContentSearch, "objectClass")) {
private static final long serialVersionUID = 1L;
@Override
public Collection<QName> loadChoices() {
return createObjectClassChoices(getModel());
}
@Override
protected void onChange(AjaxRequestTarget target) {
LOGGER.trace("Object class panel update: {}", isUseObjectClass());
updateResourceContentSearch();
mainForm.addOrReplace(initTable(getModel()));
target.add(mainForm);
}
};
objectClassPanel.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return isUseObjectClass();
}
});
add(objectClassPanel);
AjaxLink<Boolean> repoSearch = new AjaxLink<Boolean>(ID_REPO_SEARCH, new PropertyModel<>(resourceContentSearch, "resourceSearch")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
isRepoSearch = true;
getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_REPOSITORY_CONTENT).setResourceSearch(Boolean.FALSE);
getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_RESOURCE_CONTENT).setResourceSearch(Boolean.FALSE);
resourceContentSearch.getObject().setResourceSearch(Boolean.FALSE);
updateResourceContentSearch();
mainForm.addOrReplace(initRepoContent(ResourceContentTabPanel.this.getModel()));
target.add(getParent().addOrReplace(mainForm));
target.add(this);
target.add(getParent().get(ID_RESOURCE_SEARCH).add(AttributeModifier.replace("class", "btn btn-sm btn-default")));
}
@Override
protected void onBeforeRender() {
super.onBeforeRender();
if (!getModelObject().booleanValue())
add(AttributeModifier.replace("class", "btn btn-sm btn-default active"));
}
};
add(repoSearch);
AjaxLink<Boolean> resourceSearch = new AjaxLink<Boolean>(ID_RESOURCE_SEARCH, new PropertyModel<>(resourceContentSearch, "resourceSearch")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
isRepoSearch = false;
getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_REPOSITORY_CONTENT).setResourceSearch(Boolean.TRUE);
getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_RESOURCE_CONTENT).setResourceSearch(Boolean.TRUE);
updateResourceContentSearch();
resourceContentSearch.getObject().setResourceSearch(Boolean.TRUE);
mainForm.addOrReplace(initResourceContent(ResourceContentTabPanel.this.getModel()));
target.add(getParent().addOrReplace(mainForm));
target.add(this.add(AttributeModifier.append("class", " active")));
target.add(getParent().get(ID_REPO_SEARCH).add(AttributeModifier.replace("class", "btn btn-sm btn-default")));
}
@Override
protected void onBeforeRender() {
super.onBeforeRender();
getModelObject().booleanValue();
if (getModelObject().booleanValue())
add(AttributeModifier.replace("class", "btn btn-sm btn-default active"));
}
};
add(resourceSearch);
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class AssociationFromLinkExpressionEvaluator method evaluate.
@Override
public PrismValueDeltaSetTriple<PrismContainerValue<ShadowAssociationType>> evaluate(ExpressionEvaluationContext context, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
checkEvaluatorProfile(context);
String desc = context.getContextDescription();
AbstractRoleType thisRole = getRelevantRole(context);
LOGGER.trace("Evaluating association from link {} on: {}", expressionEvaluatorBean.getDescription(), thisRole);
// noinspection unchecked
TypedValue<ResourceObjectDefinition> rAssocTargetDefTypedValue = context.getVariables().get(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION);
if (rAssocTargetDefTypedValue == null || rAssocTargetDefTypedValue.getValue() == null) {
throw new ExpressionEvaluationException("No association target object class definition variable in " + desc + "; the expression may be used in a wrong place. It is only supposed to create an association.");
}
ResourceObjectDefinition associationTargetDef = (ResourceObjectDefinition) rAssocTargetDefTypedValue.getValue();
ShadowDiscriminatorType projectionDiscriminator = expressionEvaluatorBean.getProjectionDiscriminator();
if (projectionDiscriminator == null) {
throw new ExpressionEvaluationException("No projectionDiscriminator in " + desc);
}
ShadowKindType kind = projectionDiscriminator.getKind();
if (kind == null) {
throw new ExpressionEvaluationException("No kind in projectionDiscriminator in " + desc);
}
String intent = projectionDiscriminator.getIntent();
PrismContainer<ShadowAssociationType> output = outputDefinition.instantiate();
QName assocName = context.getMappingQName();
String resourceOid = associationTargetDef.getResourceOid();
List<String> candidateShadowOidList = new ArrayList<>();
// Always process the first role (myself) regardless of recursion setting
gatherCandidateShadowsFromAbstractRole(thisRole, candidateShadowOidList);
if (thisRole instanceof OrgType && matchesForRecursion((OrgType) thisRole)) {
gatherCandidateShadowsFromAbstractRoleRecurse((OrgType) thisRole, candidateShadowOidList, null, desc, context, result);
}
LOGGER.trace("Candidate shadow OIDs: {}", candidateShadowOidList);
selectMatchingShadows(candidateShadowOidList, output, resourceOid, kind, intent, assocName, context, result);
return ItemDeltaUtil.toDeltaSetTriple(output, null, prismContext);
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ResourceContentResourcePanel method createAttributeDefinitionList.
private <T extends ObjectType> List<SearchItemDefinition> createAttributeDefinitionList() {
List<SearchItemDefinition> map = new ArrayList<>();
ResourceObjectDefinition ocDef = null;
try {
if (getKind() != null) {
ocDef = getDefinitionByKind();
} else if (getObjectClass() != null) {
ocDef = getDefinitionByObjectClass();
}
} catch (SchemaException e) {
warn("Could not get determine object class definition");
return map;
}
if (ocDef == null) {
return map;
}
for (ResourceAttributeDefinition def : ocDef.getAttributeDefinitions()) {
map.add(new SearchItemDefinition(ItemPath.create(ShadowType.F_ATTRIBUTES, getAttributeName(def)), def, null));
}
return map;
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ResourceContentPanel method getTasksForKind.
private List<TaskType> getTasksForKind(List<PrismObject<TaskType>> tasks) {
List<TaskType> tasksForKind = new ArrayList<>();
for (PrismObject<TaskType> task : tasks) {
ShadowKindType taskKindValue;
@Nullable ResourceObjectSetType resourceSet = ResourceObjectSetUtil.fromTask(task.asObjectable());
if (!java.util.Objects.isNull(resourceSet)) {
taskKindValue = resourceSet.getKind();
if (Objects.isNull(taskKindValue)) {
QName taskObjectClass = resourceSet.getObjectclass();
if (Objects.isNull(taskObjectClass)) {
LOGGER.warn("Bad task definition. Task {} doesn't contain definition either of objectClass or kind/intent", task.getOid());
continue;
}
QName objectClass = getObjectClass();
if (Objects.isNull(objectClass)) {
LOGGER.trace("Trying to determine objectClass for kind: {}, intent: {}", getKind(), getIntent());
ResourceObjectDefinition objectClassDef = null;
try {
objectClassDef = getDefinitionByKind();
} catch (SchemaException e) {
LOGGER.error("Failed to search for objectClass definition. Reason: {}", e.getMessage(), e);
}
if (objectClassDef == null) {
LOGGER.warn("Cannot find any definition for kind: {}, intent: {}", getKind(), getIntent());
continue;
}
objectClass = objectClassDef.getTypeName();
}
if (QNameUtil.match(objectClass, taskObjectClass)) {
tasksForKind.add(task.asObjectable());
}
} else {
String taskIntentValue = resourceSet.getIntent();
if (StringUtils.isNotEmpty(getIntent())) {
if (getKind() == taskKindValue && getIntent().equals(taskIntentValue)) {
tasksForKind.add(task.asObjectable());
}
} else if (getKind() == taskKindValue) {
tasksForKind.add(task.asObjectable());
}
}
}
}
return tasksForKind;
}
Aggregations