Search in sources :

Example 1 with SchemaRegistry

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);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry)

Example 2 with SchemaRegistry

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;
}
Also used : SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 3 with SchemaRegistry

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;
}
Also used : ScheduleType(com.evolveum.midpoint.xml.ns._public.common.common_3.ScheduleType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) SystemException(com.evolveum.midpoint.util.exception.SystemException) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) QName(javax.xml.namespace.QName) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 4 with SchemaRegistry

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;
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) TaskEditableState(com.evolveum.midpoint.web.page.admin.server.dto.TaskEditableState) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 5 with SchemaRegistry

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();
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RestartResponseException(org.apache.wicket.RestartResponseException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Iterator(java.util.Iterator) MyPasswordQuestionsPanel(com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) SecurityQuestionAnswerType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)39 Test (org.testng.annotations.Test)26 PrismContext (com.evolveum.midpoint.prism.PrismContext)10 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)9 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)9 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)6 Task (com.evolveum.midpoint.task.api.Task)6 QName (javax.xml.namespace.QName)6 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)5 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)4 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)4 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)3 PrismObjectDefinition (com.evolveum.midpoint.prism.PrismObjectDefinition)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ConnectorConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType)3 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)2 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)2