private ObjectQuery createQuery() {
    AccountContentSearchDto dto = searchModel.getObject();
    if (StringUtils.isEmpty(dto.getSearchText())) {
      return null;
    }

    try {
      ObjectQuery query = null;

      List<ObjectFilter> conditions = new ArrayList<>();
      ObjectClassComplexTypeDefinition def = getAccountDefinition();
      if (dto.isIdentifiers()) {

        List<ResourceAttributeDefinition> identifiers = new ArrayList<>();
        if (def.getIdentifiers() != null) {
          identifiers.addAll(def.getIdentifiers());
        }

        // TODO set matching rule instead fo null
        for (ResourceAttributeDefinition attrDef : identifiers) {
          conditions.add(
              EqualFilter.createEqual(
                  new ItemPath(ShadowType.F_ATTRIBUTES, attrDef.getName()),
                  attrDef,
                  dto.getSearchText()));
        }
      }

      if (dto.isName()) {
        List<ResourceAttributeDefinition> secondaryIdentifiers = new ArrayList<>();
        if (def.getNamingAttribute() != null) {
          secondaryIdentifiers.add(def.getNamingAttribute());
        } else if (def.getSecondaryIdentifiers() != null) {
          secondaryIdentifiers.addAll(def.getSecondaryIdentifiers());
        }
        for (ResourceAttributeDefinition attrDef : secondaryIdentifiers) {
          conditions.add(
              SubstringFilter.createSubstring(
                  new ItemPath(ShadowType.F_ATTRIBUTES, attrDef.getName()),
                  attrDef,
                  dto.getSearchText()));
        }
      }

      if (!conditions.isEmpty()) {
        if (conditions.size() > 1) {
          query = ObjectQuery.createObjectQuery(OrFilter.createOr(conditions));
        } else {
          query = ObjectQuery.createObjectQuery(conditions.get(0));
        }
      }

      return query;
    } catch (Exception ex) {
      error(getString("pageUsers.message.queryError") + " " + ex.getMessage());
      LoggingUtils.logException(LOGGER, "Couldn't create query filter.", ex);
    }

    return null;
  }
  private ResourceAttributeContainer createResourceObject(String dn, String sn, String cn)
      throws SchemaException {
    // Account type is hardcoded now
    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "AccountObjectClass"));
    // Determine identifier from the schema
    ResourceAttributeContainer resourceObject =
        accountDefinition.instantiate(ShadowType.F_ATTRIBUTES);

    ResourceAttributeDefinition road =
        accountDefinition.findAttributeDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "sn"));
    ResourceAttribute roa = road.instantiate();
    roa.setValue(new PrismPropertyValue(sn));
    resourceObject.add(roa);

    road =
        accountDefinition.findAttributeDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "cn"));
    roa = road.instantiate();
    roa.setValue(new PrismPropertyValue(cn));
    resourceObject.add(roa);

    road = accountDefinition.findAttributeDefinition(ConnectorFactoryIcfImpl.ICFS_NAME);
    roa = road.instantiate();
    roa.setValue(new PrismPropertyValue(dn));
    resourceObject.add(roa);

    return resourceObject;
  }
 private PrismProperty createProperty(String propertyName, String propertyValue) {
   ObjectClassComplexTypeDefinition accountDefinition =
       resourceSchema.findObjectClassDefinition(
           new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "AccountObjectClass"));
   ResourceAttributeDefinition propertyDef =
       accountDefinition.findAttributeDefinition(
           new QName(ResourceTypeUtil.getResourceNamespace(resourceType), propertyName));
   ResourceAttribute property = propertyDef.instantiate();
   property.setValue(new PrismPropertyValue(propertyValue));
   return property;
 }
  private Collection<ResourceAttribute<?>> addSampleResourceObject(
      String name, String givenName, String familyName)
      throws CommunicationException, GenericFrameworkException, SchemaException,
          ObjectAlreadyExistsException, ConfigurationException {
    OperationResult result = new OperationResult(this.getClass().getName() + ".testAdd");

    QName objectClassQname =
        new QName(
            ResourceTypeUtil.getResourceNamespace(resourceType),
            ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME);
    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(objectClassQname);
    assertNotNull("No object class definition " + objectClassQname, accountDefinition);
    ResourceAttributeContainer resourceObject =
        accountDefinition.instantiate(ShadowType.F_ATTRIBUTES);

    ResourceAttributeDefinition<String> attributeDefinition =
        accountDefinition.findAttributeDefinition(
            new QName(
                ResourceTypeUtil.getResourceNamespace(resourceType),
                ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME));
    ResourceAttribute<String> attribute = attributeDefinition.instantiate();
    attribute.setValue(
        new PrismPropertyValue<String>("uid=" + name + ",ou=people,dc=example,dc=com"));
    resourceObject.add(attribute);

    attributeDefinition =
        accountDefinition.findAttributeDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "sn"));
    attribute = attributeDefinition.instantiate();
    attribute.setValue(new PrismPropertyValue(familyName));
    resourceObject.add(attribute);

    attributeDefinition =
        accountDefinition.findAttributeDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "cn"));
    attribute = attributeDefinition.instantiate();
    attribute.setValue(new PrismPropertyValue(givenName + " " + familyName));
    resourceObject.add(attribute);

    attributeDefinition =
        accountDefinition.findAttributeDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "givenName"));
    attribute = attributeDefinition.instantiate();
    attribute.setValue(new PrismPropertyValue(givenName));
    resourceObject.add(attribute);

    PrismObject<ShadowType> shadow = wrapInShadow(ShadowType.class, resourceObject);

    Set<Operation> operation = new HashSet<Operation>();
    Collection<ResourceAttribute<?>> resourceAttributes = cc.addObject(shadow, operation, result);
    return resourceAttributes;
  }
 private PrismProperty createProperty(String propertyName, String propertyValue) {
   ObjectClassComplexTypeDefinition accountDefinition =
       resourceSchema.findObjectClassDefinition(
           new QName(
               ResourceTypeUtil.getResourceNamespace(resourceType),
               ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME));
   ResourceAttributeDefinition propertyDef =
       accountDefinition.findAttributeDefinition(
           new QName(ResourceTypeUtil.getResourceNamespace(resourceType), propertyName));
   ResourceAttribute property = propertyDef.instantiate();
   property.setValue(new PrismPropertyValue(propertyValue));
   return property;
 }
  private ResourceAttributeContainer createResourceObject(String dn, String sn, String cn)
      throws SchemaException {
    // Account type is hardcoded now
    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            new QName(
                ResourceTypeUtil.getResourceNamespace(resourceType),
                ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME));
    // Determine identifier from the schema
    ResourceAttributeContainer resourceObject =
        accountDefinition.instantiate(ShadowType.F_ATTRIBUTES);

    ResourceAttributeDefinition road =
        accountDefinition.findAttributeDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "sn"));
    ResourceAttribute roa = road.instantiate();
    roa.setValue(new PrismPropertyValue(sn));
    resourceObject.add(roa);

    road =
        accountDefinition.findAttributeDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "cn"));
    roa = road.instantiate();
    roa.setValue(new PrismPropertyValue(cn));
    resourceObject.add(roa);

    road =
        accountDefinition.findAttributeDefinition(
            new QName(
                ResourceTypeUtil.getResourceNamespace(resourceType),
                ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME));
    roa = road.instantiate();
    roa.setValue(new PrismPropertyValue(dn));
    resourceObject.add(roa);

    return resourceObject;
  }
  @Test
  public void testResourceSchemaSanity() throws Exception {
    TestUtil.displayTestTile("testResourceSchemaSanity");

    QName objectClassQname =
        new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "AccountObjectClass");
    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(objectClassQname);
    assertNotNull("No object class definition " + objectClassQname, accountDefinition);
    assertEquals(
        "Object class " + objectClassQname + " is not account",
        ShadowKindType.ACCOUNT,
        accountDefinition.getKind());
    assertTrue(
        "Object class " + objectClassQname + " is not default account",
        accountDefinition.isDefaultInAKind());
    assertFalse("Object class " + objectClassQname + " is empty", accountDefinition.isEmpty());
    assertFalse("Object class " + objectClassQname + " is empty", accountDefinition.isIgnored());

    Collection<? extends ResourceAttributeDefinition> identifiers =
        accountDefinition.getIdentifiers();
    assertNotNull("Null identifiers for " + objectClassQname, identifiers);
    assertFalse("Empty identifiers for " + objectClassQname, identifiers.isEmpty());
    // TODO

    ResourceAttributeDefinition attributeDefinition =
        accountDefinition.findAttributeDefinition(ConnectorFactoryIcfImpl.ICFS_UID);
    assertNotNull(
        "No definition for attribute " + ConnectorFactoryIcfImpl.ICFS_UID, attributeDefinition);
    assertTrue(
        "Attribute " + ConnectorFactoryIcfImpl.ICFS_UID + " in not an identifier",
        attributeDefinition.isIdentifier(accountDefinition));
    assertTrue(
        "Attribute " + ConnectorFactoryIcfImpl.ICFS_UID + " in not in identifiers list",
        identifiers.contains(attributeDefinition));
  }
  @Test
  public void test020ResourceSchemaSanity() throws Exception {
    final String TEST_NAME = "test020ResourceSchemaSanity";
    TestUtil.displayTestTile(TEST_NAME);

    QName objectClassQname =
        new QName(
            ResourceTypeUtil.getResourceNamespace(resourceType),
            ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME);
    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(objectClassQname);
    assertNotNull("No object class definition " + objectClassQname, accountDefinition);
    //		assertEquals("Object class " + objectClassQname + " is not account", ShadowKindType.ACCOUNT,
    // accountDefinition.getKind());
    //		assertTrue("Object class " + objectClassQname + " is not default account",
    // accountDefinition.isDefaultInAKind());
    assertFalse("Object class " + objectClassQname + " is empty", accountDefinition.isEmpty());
    assertFalse("Object class " + objectClassQname + " is empty", accountDefinition.isIgnored());

    Collection<? extends ResourceAttributeDefinition> identifiers =
        accountDefinition.getIdentifiers();
    assertNotNull("Null identifiers for " + objectClassQname, identifiers);
    assertFalse("Empty identifiers for " + objectClassQname, identifiers.isEmpty());

    ResourceAttributeDefinition<String> idPrimaryDef =
        accountDefinition.findAttributeDefinition(
            new QName(
                ResourceTypeUtil.getResourceNamespace(resourceType),
                ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME));
    assertNotNull(
        "No definition for attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME,
        idPrimaryDef);
    assertTrue(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME
            + " in not an identifier",
        idPrimaryDef.isIdentifier(accountDefinition));
    assertTrue(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME
            + " in not in identifiers list",
        identifiers.contains(idPrimaryDef));
    assertEquals(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME
            + " has wrong native name",
        ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME,
        idPrimaryDef.getNativeAttributeName());
    assertEquals(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME
            + " has wrong framework name",
        Uid.NAME,
        idPrimaryDef.getFrameworkAttributeName());

    ResourceAttributeDefinition<String> idSecondaryDef =
        accountDefinition.findAttributeDefinition(
            new QName(
                ResourceTypeUtil.getResourceNamespace(resourceType),
                ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME));
    assertNotNull(
        "No definition for attribute " + ConnectorFactoryIcfImpl.ICFS_NAME, idSecondaryDef);
    assertTrue(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME
            + " in not secondary identifier",
        idSecondaryDef.isSecondaryIdentifier(accountDefinition));
    assertFalse(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME
            + " in in identifiers list and it should NOT be",
        identifiers.contains(idSecondaryDef));
    assertTrue(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME
            + " in not in secomdary identifiers list",
        accountDefinition.getSecondaryIdentifiers().contains(idSecondaryDef));
    assertEquals(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME
            + " has wrong native name",
        ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME,
        idSecondaryDef.getNativeAttributeName());
    assertEquals(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME
            + " has wrong framework name",
        Name.NAME,
        idSecondaryDef.getFrameworkAttributeName());

    assertEquals("Unexpected identifiers: " + identifiers, 1, identifiers.size());
    assertEquals(
        "Unexpected secondary identifiers: " + accountDefinition.getSecondaryIdentifiers(),
        1,
        accountDefinition.getSecondaryIdentifiers().size());
  }