use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.
the class SearchFactory method findObjectDefinition.
private static <T extends ObjectType> PrismObjectDefinition findObjectDefinition(Class<T> type, ResourceShadowDiscriminator discriminator, ModelServiceLocator modelServiceLocator) {
try {
if (Modifier.isAbstract(type.getModifiers())) {
SchemaRegistry registry = modelServiceLocator.getPrismContext().getSchemaRegistry();
return registry.findObjectDefinitionByCompileTimeClass(type);
}
Task task = modelServiceLocator.createSimpleTask(LOAD_OBJECT_DEFINITION);
OperationResult result = task.getResult();
PrismObject empty = modelServiceLocator.getPrismContext().createObject(type);
if (ShadowType.class.equals(type)) {
return modelServiceLocator.getModelInteractionService().getEditShadowDefinition(discriminator, AuthorizationPhaseType.REQUEST, task, result);
} else {
return modelServiceLocator.getModelInteractionService().getEditObjectDefinition(empty, AuthorizationPhaseType.REQUEST, task, result);
}
} catch (SchemaException | ConfigurationException | ObjectNotFoundException ex) {
throw new SystemException(ex);
}
}
use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.
the class SearchFactory method createSearch.
public static <T extends ObjectType> Search createSearch(Class<T> type, ResourceShadowDiscriminator discriminator, ModelServiceLocator modelServiceLocator, boolean useDefsFromSuperclass) {
PrismObjectDefinition objectDef = findObjectDefinition(type, discriminator, modelServiceLocator);
Map<ItemPath, ItemDefinition> availableDefs = getAvailableDefinitions(objectDef, useDefsFromSuperclass);
boolean isFullTextSearchEnabled = isFullTextSearchEnabled(modelServiceLocator, type);
Search search = new Search(type, availableDefs, isFullTextSearchEnabled, getDefaultSearchType(modelServiceLocator, type));
SchemaRegistry registry = modelServiceLocator.getPrismContext().getSchemaRegistry();
PrismObjectDefinition objDef = registry.findObjectDefinitionByCompileTimeClass(ObjectType.class);
PrismPropertyDefinition def = objDef.findPropertyDefinition(ObjectType.F_NAME);
SearchItem item = search.addItem(def);
if (item != null) {
item.setFixed(true);
}
return search;
}
use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.
the class PageTaskAdd method createTask.
private TaskType createTask(TaskAddDto dto) throws SchemaException {
TaskType task = new TaskType();
MidPointPrincipal owner = SecurityUtils.getPrincipalUser();
ObjectReferenceType ownerRef = new ObjectReferenceType();
ownerRef.setOid(owner.getOid());
ownerRef.setType(owner.getUser().COMPLEX_TYPE);
task.setOwnerRef(ownerRef);
task.setCategory(dto.getCategory());
String handlerUri = getTaskManager().getHandlerUriForCategory(dto.getCategory());
if (handlerUri == null) {
throw new SystemException("Cannot determine task handler URI for category " + dto.getCategory());
}
task.setHandlerUri(handlerUri);
ObjectReferenceType objectRef;
if (dto.getResource() != null) {
objectRef = new ObjectReferenceType();
objectRef.setOid(dto.getResource().getOid());
objectRef.setType(ResourceType.COMPLEX_TYPE);
task.setObjectRef(objectRef);
}
task.setName(WebComponentUtil.createPolyFromOrigString(dto.getName()));
task.setRecurrence(dto.getReccuring() ? TaskRecurrenceType.RECURRING : TaskRecurrenceType.SINGLE);
task.setBinding(dto.getBound() ? TaskBindingType.TIGHT : TaskBindingType.LOOSE);
ScheduleType schedule = new ScheduleType();
schedule.setInterval(dto.getInterval());
schedule.setCronLikePattern(dto.getCron());
schedule.setEarliestStartTime(MiscUtil.asXMLGregorianCalendar(dto.getNotStartBefore()));
schedule.setLatestStartTime(MiscUtil.asXMLGregorianCalendar(dto.getNotStartAfter()));
schedule.setMisfireAction(dto.getMisfireAction());
task.setSchedule(schedule);
if (dto.getSuspendedState()) {
task.setExecutionStatus(TaskExecutionStatusType.SUSPENDED);
} else {
task.setExecutionStatus(TaskExecutionStatusType.RUNNABLE);
}
if (dto.getThreadStop() != null) {
task.setThreadStopAction(dto.getThreadStop());
} else {
// fill-in default
if (dto.getRunUntilNodeDown() == true) {
task.setThreadStopAction(ThreadStopActionType.CLOSE);
} else {
task.setThreadStopAction(ThreadStopActionType.RESTART);
}
}
if (dto.isDryRun()) {
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_DRY_RUN);
PrismProperty dryRun = prismTask.findOrCreateProperty(path);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_DRY_RUN);
dryRun.setDefinition(def);
dryRun.setRealValue(true);
}
if (dto.getFocusType() != null) {
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECT_TYPE);
PrismProperty focusType = prismTask.findOrCreateProperty(path);
focusType.setRealValue(dto.getFocusType());
}
if (dto.getKind() != null) {
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND);
PrismProperty kind = prismTask.findOrCreateProperty(path);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_KIND);
kind.setDefinition(def);
kind.setRealValue(dto.getKind());
}
if (dto.getIntent() != null && StringUtils.isNotEmpty(dto.getIntent())) {
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT);
PrismProperty intent = prismTask.findOrCreateProperty(path);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_INTENT);
intent.setDefinition(def);
intent.setRealValue(dto.getIntent());
}
if (dto.getObjectClass() != null && StringUtils.isNotEmpty(dto.getObjectClass())) {
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.OBJECTCLASS_PROPERTY_NAME);
PrismProperty objectClassProperty = prismTask.findOrCreateProperty(path);
QName objectClass = null;
for (QName q : model.getObject().getObjectClassList()) {
if (q.getLocalPart().equals(dto.getObjectClass())) {
objectClass = q;
}
}
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.OBJECTCLASS_PROPERTY_NAME);
objectClassProperty.setDefinition(def);
objectClassProperty.setRealValue(objectClass);
}
return task;
}
use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.
the class PageTaskController method getDeltasToExecute.
private List<ItemDelta<?, ?>> getDeltasToExecute(TaskDto dto) throws SchemaException {
List<ItemDelta<?, ?>> rv = new ArrayList<>();
TaskEditableState orig = dto.getOriginalEditableState();
TaskEditableState curr = dto.getCurrentEditableState();
if (!StringUtils.equals(orig.getName(), curr.getName())) {
String name = curr.getName() != null ? curr.getName() : "";
addDelta(rv, TaskType.F_NAME, new PolyString(name));
}
if (!StringUtils.equals(orig.getDescription(), curr.getDescription())) {
addDelta(rv, TaskType.F_DESCRIPTION, curr.getDescription());
}
ScheduleType origSchedule = orig.getScheduleType();
ScheduleType currSchedule = curr.getScheduleType();
if (!origSchedule.equals(currSchedule)) {
if (dto.getTaskType().getSchedule() != null) {
currSchedule.setLatestFinishTime(dto.getTaskType().getSchedule().getLatestFinishTime());
}
addDelta(rv, TaskType.F_SCHEDULE, currSchedule);
}
if (orig.isRecurring() != curr.isRecurring()) {
addDelta(rv, TaskType.F_RECURRENCE, curr.isRecurring() ? TaskRecurrenceType.RECURRING : TaskRecurrenceType.SINGLE);
}
if (orig.isBound() != curr.isBound()) {
addDelta(rv, TaskType.F_BINDING, curr.isBound() ? TaskBindingType.TIGHT : TaskBindingType.LOOSE);
}
if (orig.getThreadStopActionType() != curr.getThreadStopActionType()) {
addDelta(rv, TaskType.F_THREAD_STOP_ACTION, curr.getThreadStopActionType());
}
if (!ObjectUtils.equals(orig.getWorkerThreads(), curr.getWorkerThreads())) {
SchemaRegistry registry = parentPage.getPrismContext().getSchemaRegistry();
PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_WORKER_THREADS);
rv.add(DeltaBuilder.deltaFor(TaskType.class, parentPage.getPrismContext()).item(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_WORKER_THREADS), def).replace(curr.getWorkerThreads()).asItemDelta());
}
rv.addAll(dto.getHandlerDto().getDeltasToExecute(orig.getHandlerSpecificState(), curr.getHandlerSpecificState(), parentPage.getPrismContext()));
return rv;
}
use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.
the class PageMyPasswordQuestions method updateQuestions.
private void updateQuestions(String useroid, AjaxRequestTarget target) {
Task task = createSimpleTask(OPERATION_SAVE_QUESTIONS);
OperationResult result = new OperationResult(OPERATION_SAVE_QUESTIONS);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
SecurityQuestionAnswerType[] answerTypeList = new SecurityQuestionAnswerType[questionNumber];
try {
int listnum = 0;
for (Iterator iterator = pqPanels.iterator(); iterator.hasNext(); ) {
MyPasswordQuestionsPanel type = (MyPasswordQuestionsPanel) iterator.next();
SecurityQuestionAnswerType answerType = new SecurityQuestionAnswerType();
ProtectedStringType answer = new ProtectedStringType();
answer.setClearValue(((TextField<String>) type.get(MyPasswordQuestionsPanel.F_ANSWER)).getModelObject());
answerType.setQuestionAnswer(answer);
//used apache's unescapeHtml method for special chars like \'
String results = StringEscapeUtils.unescapeHtml((type.get(MyPasswordQuestionsPanel.F_QUESTION)).getDefaultModelObjectAsString());
answerType.setQuestionIdentifier(getQuestionIdentifierFromQuestion(results));
answerTypeList[listnum] = answerType;
listnum++;
}
//if(answerTypeList.length !=)
// fill in answerType data here
ItemPath path = new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_SECURITY_QUESTIONS, SecurityQuestionsCredentialsType.F_QUESTION_ANSWER);
ObjectDelta<UserType> objectDelta = ObjectDelta.createModificationReplaceContainer(UserType.class, useroid, path, getPrismContext(), answerTypeList);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
getModelService().executeChanges(deltas, null, task, result);
/*
System.out.println("getModel");
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
PasswordQuestionsDto dto = new PasswordQuestionsDto();
PrismObjectDefinition objDef =registry.findObjectDefinitionByCompileTimeClass(UserType.class);
Class<? extends ObjectType> type = UserType.class;
final ItemPath valuePath = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS,
CredentialsType.F_SECURITY_QUESTIONS, SecurityQuestionsCredentialsType.F_QUESTION_ANSWER);
SecurityQuestionAnswerType secQuesAnsType= new SecurityQuestionAnswerType();
ProtectedStringType protStrType= new ProtectedStringType();
protStrType.setClearValue("deneme");
secQuesAnsType.setQuestionAnswer(protStrType);
dto.setSecurityAnswers(new ArrayList<SecurityQuestionAnswerType>());
dto.getSecurityAnswers().add(secQuesAnsType);
PropertyDelta delta = PropertyDelta.createModificationReplaceProperty(valuePath, objDef, dto.getSecurityAnswers().get(0).getQuestionAnswer());
// PropertyDelta delta= PropertyDelta.createModifica
System.out.println("Update Questions3");
deltas.add(ObjectDelta.createModifyDelta(useroid, delta, type, getPrismContext()));
System.out.println("Update Questions4");
getModelService().executeChanges(deltas, null, createSimpleTask(OPERATION_SAVE_QUESTIONS), result);
System.out.println("Update Questions5");
*/
success(getString("message.success"));
target.add(getFeedbackPanel());
} catch (Exception ex) {
error(getString("message.error"));
target.add(getFeedbackPanel());
ex.printStackTrace();
}
}
Aggregations