use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.
the class SynchronizationServiceImpl method satisfyTaskConstraints.
private boolean satisfyTaskConstraints(ObjectSynchronizationType synchronizationPolicy, Task task) {
PrismProperty<ShadowKindType> kind = task.getExtensionProperty(SchemaConstants.MODEL_EXTENSION_KIND);
if (kind != null && !kind.isEmpty()) {
ShadowKindType kindValue = kind.getRealValue();
ShadowKindType policyKind = synchronizationPolicy.getKind();
if (policyKind == null) {
// TODO is this ok? [med]
policyKind = ShadowKindType.ACCOUNT;
}
if (!policyKind.equals(kindValue)) {
return false;
}
}
PrismProperty<String> intent = task.getExtensionProperty(SchemaConstants.MODEL_EXTENSION_INTENT);
if (intent != null && !intent.isEmpty()) {
String intentValue = intent.getRealValue();
if (StringUtils.isEmpty(synchronizationPolicy.getIntent())) {
return false;
}
if (!synchronizationPolicy.getIntent().equals(intentValue)) {
return false;
}
}
return true;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.
the class ResourceContentPanel method newTaskPerformed.
private void newTaskPerformed(String category, AjaxRequestTarget target) {
TaskType taskType = new TaskType();
PrismProperty<ShadowKindType> pKind;
try {
pKind = taskType.asPrismObject().findOrCreateProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND));
pKind.setRealValue(getKind());
} catch (SchemaException e) {
getSession().warn("Could not set kind for new task " + e.getMessage());
}
PrismProperty<String> pIntent;
try {
pIntent = taskType.asPrismObject().findOrCreateProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT));
pIntent.setRealValue(getIntent());
} catch (SchemaException e) {
getSession().warn("Could not set kind for new task " + e.getMessage());
}
PrismObject<ResourceType> resource = getResourceModel().getObject();
taskType.setObjectRef(ObjectTypeUtil.createObjectRef(resource));
taskType.setCategory(category);
setResponsePage(new PageTaskAdd(taskType));
;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.
the class SynchronizationUtils method isPolicyApplicable.
public static boolean isPolicyApplicable(QName objectClass, ShadowKindType kind, String intent, ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException {
List<QName> policyObjectClasses = synchronizationPolicy.getObjectClass();
if (policyObjectClasses == null || policyObjectClasses.isEmpty()) {
String policyIntent = synchronizationPolicy.getIntent();
ShadowKindType policyKind = synchronizationPolicy.getKind();
ObjectClassComplexTypeDefinition policyObjectClass = null;
RefinedResourceSchema schema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
if (schema == null) {
throw new SchemaException("No schema defined in resource. Possible configuration problem?");
}
if (policyKind == null && policyIntent == null) {
policyObjectClass = schema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
}
if (policyKind != null) {
if (StringUtils.isEmpty(policyIntent)) {
policyObjectClass = schema.findDefaultObjectClassDefinition(policyKind);
} else {
policyObjectClass = schema.findObjectClassDefinition(policyKind, policyIntent);
}
}
if (policyObjectClass != null && !policyObjectClass.getTypeName().equals(objectClass)) {
return false;
}
}
if (policyObjectClasses != null && !policyObjectClasses.isEmpty()) {
if (!QNameUtil.contains(policyObjectClasses, objectClass)) {
return false;
}
}
// kind
ShadowKindType policyKind = synchronizationPolicy.getKind();
if (policyKind != null && kind != null && !policyKind.equals(kind)) {
return false;
}
// intent
// TODO is the intent always present in shadow at this time? [med]
String policyIntent = synchronizationPolicy.getIntent();
if (policyIntent != null && intent != null && !MiscSchemaUtil.equalsIntent(intent, policyIntent)) {
return false;
}
return true;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.
the class PageAccounts method initSearchForm.
private void initSearchForm(Form searchForm) {
BasicSearchPanel<AccountDetailsSearchDto> basicSearch = new BasicSearchPanel<AccountDetailsSearchDto>(ID_SEARCH_BASIC) {
@Override
protected IModel<String> createSearchTextModel() {
return new PropertyModel<>(searchModel, AccountDetailsSearchDto.F_SEARCH_TEXT);
}
@Override
protected void searchPerformed(AjaxRequestTarget target) {
PageAccounts.this.searchPerformed(target);
}
@Override
protected void clearSearchPerformed(AjaxRequestTarget target) {
PageAccounts.this.clearSearchPerformed(target);
}
};
basicSearch.setOutputMarkupId(true);
searchForm.add(basicSearch);
DropDownChoice failedOperationType = new DropDownChoice<>(ID_SEARCH_FAILED_OPERATION_TYPE, new PropertyModel<FailedOperationTypeType>(searchModel, AccountDetailsSearchDto.F_FAILED_OPERATION_TYPE), WebComponentUtil.createReadonlyModelFromEnum(FailedOperationTypeType.class), new EnumChoiceRenderer<FailedOperationTypeType>(this));
failedOperationType.add(new OnChangeAjaxBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
searchPerformed(target);
}
});
failedOperationType.setOutputMarkupId(true);
failedOperationType.setNullValid(true);
searchForm.add(failedOperationType);
DropDownChoice kind = new DropDownChoice<>(ID_SEARCH_KIND, new PropertyModel<ShadowKindType>(searchModel, AccountDetailsSearchDto.F_KIND), WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class), new EnumChoiceRenderer<ShadowKindType>(this));
kind.add(new OnChangeAjaxBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
searchPerformed(target);
}
});
kind.setOutputMarkupId(true);
kind.setNullValid(true);
searchForm.add(kind);
DropDownChoice intent = new DropDownChoice<>(ID_SEARCH_INTENT, new PropertyModel<String>(searchModel, AccountDetailsSearchDto.F_INTENT), createIntentChoices(), new StringChoiceRenderer(null));
intent.setNullValid(true);
intent.add(new OnChangeAjaxBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
searchPerformed(target);
}
});
intent.setOutputMarkupId(true);
searchForm.add(intent);
AutoCompleteTextField<String> objectClass = new AutoCompleteTextField<String>(ID_SEARCH_OBJECT_CLASS, new PropertyModel<String>(searchModel, AccountDetailsSearchDto.F_OBJECT_CLASS)) {
@Override
protected Iterator<String> getChoices(String input) {
if (Strings.isEmpty(input)) {
List<String> emptyList = Collections.emptyList();
return emptyList.iterator();
}
AccountDetailsSearchDto dto = searchModel.getObject();
List<QName> accountObjectClassList = dto.getObjectClassList();
List<String> choices = new ArrayList<>(AUTO_COMPLETE_LIST_SIZE);
for (QName s : accountObjectClassList) {
if (s.getLocalPart().toLowerCase().startsWith(input.toLowerCase())) {
choices.add(s.getLocalPart());
if (choices.size() == AUTO_COMPLETE_LIST_SIZE) {
break;
}
}
}
return choices.iterator();
}
};
objectClass.add(AttributeModifier.replace("placeholder", createStringResource("PageAccounts.accounts.objectClass")));
objectClass.setOutputMarkupId(true);
objectClass.add(createObjectClassValidator());
objectClass.add(new SearchFormEnterBehavior(basicSearch.getSearchButton()));
searchForm.add(objectClass);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.
the class ShadowIntegrityCheckResultHandler method checkShadow.
private void checkShadow(ShadowCheckResult checkResult, PrismObject<ShadowType> shadow, Task workerTask, OperationResult result) throws SchemaException {
ShadowType shadowType = shadow.asObjectable();
ObjectReferenceType resourceRef = shadowType.getResourceRef();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Checking shadow {} (resource {})", ObjectTypeUtil.toShortString(shadowType), resourceRef != null ? resourceRef.getOid() : "(null)");
}
statistics.incrementShadows();
if (resourceRef == null) {
checkResult.recordError(Statistics.NO_RESOURCE_OID, new SchemaException("No resourceRef"));
fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE_OID);
applyFixes(checkResult, shadow, workerTask, result);
return;
}
String resourceOid = resourceRef.getOid();
if (resourceOid == null) {
checkResult.recordError(Statistics.NO_RESOURCE_OID, new SchemaException("Null resource OID"));
fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE_OID);
applyFixes(checkResult, shadow, workerTask, result);
return;
}
PrismObject<ResourceType> resource = resources.get(resourceOid);
if (resource == null) {
statistics.incrementResources();
try {
resource = provisioningService.getObject(ResourceType.class, resourceOid, null, workerTask, result);
} catch (ObjectNotFoundException e) {
checkResult.recordError(Statistics.NO_RESOURCE, new ObjectNotFoundException("Resource object does not exist: " + e.getMessage(), e));
fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE);
applyFixes(checkResult, shadow, workerTask, result);
return;
} catch (SchemaException e) {
checkResult.recordError(Statistics.CANNOT_GET_RESOURCE, new SchemaException("Resource object has schema problems: " + e.getMessage(), e));
return;
} catch (CommonException | RuntimeException e) {
checkResult.recordError(Statistics.CANNOT_GET_RESOURCE, new SystemException("Resource object cannot be fetched for some reason: " + e.getMessage(), e));
return;
}
resources.put(resourceOid, resource);
}
checkResult.setResource(resource);
ShadowKindType kind = shadowType.getKind();
if (kind == null) {
// TODO or simply assume account?
checkResult.recordError(Statistics.NO_KIND_SPECIFIED, new SchemaException("No kind specified"));
return;
}
if (checkExtraData) {
checkOrFixShadowActivationConsistency(checkResult, shadow, fixExtraData);
}
PrismObject<ShadowType> fetchedShadow = null;
if (checkFetch) {
fetchedShadow = fetchShadow(checkResult, shadow, resource, workerTask, result);
if (fetchedShadow != null) {
shadow.setUserData(KEY_EXISTS_ON_RESOURCE, "true");
}
}
if (checkOwners) {
List<PrismObject<FocusType>> owners = searchOwners(shadow, result);
if (owners != null) {
shadow.setUserData(KEY_OWNERS, owners);
if (owners.size() > 1) {
checkResult.recordError(Statistics.MULTIPLE_OWNERS, new SchemaException("Multiple owners: " + owners));
}
}
if (shadowType.getSynchronizationSituation() == SynchronizationSituationType.LINKED && (owners == null || owners.isEmpty())) {
checkResult.recordError(Statistics.LINKED_WITH_NO_OWNER, new SchemaException("Linked shadow with no owner"));
}
if (shadowType.getSynchronizationSituation() != SynchronizationSituationType.LINKED && owners != null && !owners.isEmpty()) {
checkResult.recordError(Statistics.NOT_LINKED_WITH_OWNER, new SchemaException("Shadow with an owner but not marked as linked (marked as " + shadowType.getSynchronizationSituation() + ")"));
}
}
String intent = shadowType.getIntent();
if (checkIntents && (intent == null || intent.isEmpty())) {
checkResult.recordWarning(Statistics.NO_INTENT_SPECIFIED, "None or empty intent");
}
if (fixIntents && (intent == null || intent.isEmpty())) {
doFixIntent(checkResult, fetchedShadow, shadow, resource, workerTask, result);
}
Pair<String, ShadowKindType> key = new ImmutablePair<>(resourceOid, kind);
ObjectTypeContext context = contextMap.get(key);
if (context == null) {
context = new ObjectTypeContext();
context.setResource(resource);
RefinedResourceSchema resourceSchema;
try {
resourceSchema = RefinedResourceSchemaImpl.getRefinedSchema(context.getResource(), LayerType.MODEL, prismContext);
} catch (SchemaException e) {
checkResult.recordError(Statistics.CANNOT_GET_REFINED_SCHEMA, new SchemaException("Couldn't derive resource schema: " + e.getMessage(), e));
return;
}
if (resourceSchema == null) {
checkResult.recordError(Statistics.NO_RESOURCE_REFINED_SCHEMA, new SchemaException("No resource schema"));
return;
}
context.setObjectClassDefinition(resourceSchema.getRefinedDefinition(kind, shadowType));
if (context.getObjectClassDefinition() == null) {
// TODO or warning only?
checkResult.recordError(Statistics.NO_OBJECT_CLASS_REFINED_SCHEMA, new SchemaException("No refined object class definition for kind=" + kind + ", intent=" + intent));
return;
}
contextMap.put(key, context);
}
try {
provisioningService.applyDefinition(shadow, workerTask, result);
} catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
checkResult.recordError(Statistics.OTHER_FAILURE, new SystemException("Couldn't apply definition to shadow from repo", e));
return;
}
Set<RefinedAttributeDefinition<?>> identifiers = new HashSet<>();
Collection<? extends RefinedAttributeDefinition<?>> primaryIdentifiers = context.getObjectClassDefinition().getPrimaryIdentifiers();
identifiers.addAll(primaryIdentifiers);
identifiers.addAll(context.getObjectClassDefinition().getSecondaryIdentifiers());
PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer == null) {
// might happen on unfinished shadows?
checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("No attributes container"));
return;
}
for (RefinedAttributeDefinition<?> identifier : identifiers) {
PrismProperty property = attributesContainer.getValue().findProperty(identifier.getName());
if (property == null || property.size() == 0) {
checkResult.recordWarning(Statistics.OTHER_FAILURE, "No value for identifier " + identifier.getName());
continue;
}
if (property.size() > 1) {
// we don't expect multi-valued identifiers
checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("Multi-valued identifier " + identifier.getName() + " with values " + property.getValues()));
continue;
}
// size == 1
String value = (String) property.getValue().getValue();
if (value == null) {
checkResult.recordWarning(Statistics.OTHER_FAILURE, "Null value for identifier " + identifier.getName());
continue;
}
if (checkUniqueness) {
if (!checkDuplicatesOnPrimaryIdentifiersOnly || primaryIdentifiers.contains(identifier)) {
addIdentifierValue(checkResult, context, identifier.getName(), value, shadow);
}
}
if (checkNormalization) {
doCheckNormalization(checkResult, identifier, value, context);
}
}
applyFixes(checkResult, shadow, workerTask, result);
}
Aggregations