/**
   * Assign two resources to a user. One of them is looney, the other is not. The result should be
   * that the account on the good resource is created.
   */
  private void testAssignTwoResoures(final String TEST_NAME, String badResourceOid)
      throws Exception {
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    Task task =
        taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);

    ObjectDelta<UserType> userDelta =
        createAccountAssignmentUserDelta(USER_JACK_OID, badResourceOid, null, true);
    userDelta.addModification(createAccountAssignmentModification(RESOURCE_DUMMY_OID, null, true));
    display("input delta", userDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas =
        MiscSchemaUtil.createCollection(userDelta);

    // WHEN
    modelService.executeChanges(deltas, null, task, result);

    // THEN
    result.computeStatus();
    display("executeChanges result", result);

    // TODO: ugly hack, see MID-1248
    if ("test401AssignTwoResouresBroken".equals(TEST_NAME)) {
      assertEquals(
          "Expected partial error in result",
          OperationResultStatus.PARTIAL_ERROR,
          result.getStatus());
    }

    DummyAccount jackDummyAccount = dummyResource.getAccountByUsername(USER_JACK_USERNAME);
    assertNotNull("No jack dummy account", jackDummyAccount);
  }
 @Override
 public List<? extends RefinedObjectClassDefinition> getRefinedDefinitions(ShadowKindType kind) {
   List<RefinedObjectClassDefinition> rv = new ArrayList<>();
   for (RefinedObjectClassDefinition def : getRefinedDefinitions()) {
     if (MiscSchemaUtil.matchesKind(kind, def.getKind())) {
       rv.add(def);
     }
   }
   return rv;
 }
 @Override
 public List<ObjectReferenceType> prepareApprovedBy(ProcessEvent event) {
   List<ObjectReferenceType> retval = new ArrayList<ObjectReferenceType>();
   if (!ApprovalUtils.isApproved(getAnswer(event.getVariables()))) {
     return retval;
   }
   List<Decision> allDecisions = event.getVariable(ProcessVariableNames.ALL_DECISIONS, List.class);
   for (Decision decision : allDecisions) {
     if (decision.isApproved()) {
       retval.add(
           MiscSchemaUtil.createObjectReference(
               decision.getApproverOid(), SchemaConstants.C_USER_TYPE));
     }
   }
   return retval;
 }
  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();
    }
  }