protected <T extends ObjectType> PrismObject<T> searchObjectByName(Class<T> type, String name, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException { ObjectQuery query = ObjectQueryUtil.createNameQuery(name, prismContext); List<PrismObject<T>> foundObjects = modelService.searchObjects(type, query, null, task, result); if (foundObjects.isEmpty()) { return null; } if (foundObjects.size() > 1) { throw new IllegalStateException("More than one object found for type "+type+" and name '"+name+"'"); } return foundObjects.iterator().next(); }
public static ObjectQuery createNameQuery(String name, PrismContext prismContext) throws SchemaException { PolyString polyName = new PolyString(name); return createNameQuery(polyName, prismContext); }
public static ObjectQuery createNameQuery(PolyStringType name, PrismContext prismContext) throws SchemaException { return createNameQuery(name.toPolyString(), prismContext); }
protected ObjectQuery createNameQuery(String name) throws SchemaException { return ObjectQueryUtil.createNameQuery(PrismTestUtil.createPolyString(name), prismContext); }
private boolean campaignExists(String name, OperationResult result) throws SchemaException { ObjectQuery query = ObjectQueryUtil.createNameQuery(AccessCertificationCampaignType.class, prismContext, name); SearchResultList<PrismObject<AccessCertificationCampaignType>> existingCampaigns = repositoryService.searchObjects(AccessCertificationCampaignType.class, query, null, result); return !existingCampaigns.isEmpty(); }
@Override public OrgType getOrgByName(String name, boolean preAuthorized) throws SchemaException, SecurityViolationException { PolyString polyName = new PolyString(name); ObjectQuery q = ObjectQueryUtil.createNameQuery(polyName, prismContext); List<PrismObject<OrgType>> result = searchObjects(OrgType.class, q, getCurrentResult(), preAuthorized); if (result.isEmpty()) { return null; } if (result.size() > 1) { throw new IllegalStateException("More than one organizational unit with the name '" + name + "' (there are " + result.size() + " of them)"); } return result.get(0).asObjectable(); }
@Override public <T extends ObjectType> T searchObjectByName(Class<T> type, String name) throws SecurityViolationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SchemaException, ExpressionEvaluationException { ObjectQuery nameQuery = ObjectQueryUtil.createNameQuery(name, prismContext); List<PrismObject<T>> foundObjects = modelService .searchObjects(type, nameQuery, getDefaultGetOptionCollection(), getCurrentTask(), getCurrentResult()); if (foundObjects.isEmpty()) { return null; } if (foundObjects.size() > 1) { throw new IllegalStateException("More than one object found for type " + type + " and name '" + name + "'"); } return foundObjects.iterator().next().asObjectable(); }
@Override public <T extends ObjectType> T searchObjectByName(Class<T> type, PolyStringType name) throws SecurityViolationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SchemaException, ExpressionEvaluationException { ObjectQuery nameQuery = ObjectQueryUtil.createNameQuery(name, prismContext); List<PrismObject<T>> foundObjects = modelService .searchObjects(type, nameQuery, getDefaultGetOptionCollection(), getCurrentTask(), getCurrentResult()); if (foundObjects.isEmpty()) { return null; } if (foundObjects.size() > 1) { throw new IllegalStateException("More than one object found for type " + type + " and name '" + name + "'"); } return foundObjects.iterator().next().asObjectable(); }
@Override public <T extends ObjectType> T searchObjectByName(Class<T> type, PolyString name) throws SecurityViolationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SchemaException, ExpressionEvaluationException { ObjectQuery nameQuery = ObjectQueryUtil.createNameQuery(name, prismContext); List<PrismObject<T>> foundObjects = modelService .searchObjects(type, nameQuery, getDefaultGetOptionCollection(), getCurrentTask(), getCurrentResult()); if (foundObjects.isEmpty()) { return null; } if (foundObjects.size() > 1) { throw new IllegalStateException("More than one object found for type " + type + " and name '" + name + "'"); } return foundObjects.iterator().next().asObjectable(); }
@Override public SearchResultList<PrismObject<UserType>> run() { Task task = getTaskManager().createTaskInstance("Search user by name"); OperationResult result = task.getResult(); SearchResultList<PrismObject<UserType>> users; try { users = getModel().searchObjects(UserType.class, ObjectQueryUtil.createNameQuery(userName, prismContext), null, task, result); } catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) { return null; } finally { SecurityContextHolder.getContext().setAuthentication(null); } return users; } });
public static <O extends ObjectType> ObjectQuery createNameQuery(PrismObject<O> object) throws SchemaException { return createNameQuery(object.asObjectable().getName(), object.getPrismContext()); }
public static ObjectQuery createNameQuery(ObjectType object) throws SchemaException { return createNameQuery(object.getName(), object.asPrismObject().getPrismContext()); }
public PrismObject<NodeType> getNodeById(String nodeIdentifier, OperationResult result) throws ObjectNotFoundException { try { // QueryType q = QueryUtil.createNameQuery(nodeIdentifier); // TODO change to query-by-node-id ObjectQuery q = ObjectQueryUtil.createNameQuery(NodeType.class, taskManager.getPrismContext(), nodeIdentifier); List<PrismObject<NodeType>> nodes = taskManager.getRepositoryService().searchObjects(NodeType.class, q, null, result); if (nodes.isEmpty()) { // result.recordFatalError("A node with identifier " + nodeIdentifier + " does not exist."); throw new ObjectNotFoundException("A node with identifier " + nodeIdentifier + " does not exist."); } else if (nodes.size() > 1) { throw new SystemException("Multiple nodes with the same identifier '" + nodeIdentifier + "' in the repository."); } else { return nodes.get(0); } } catch (SchemaException e) { // should not occur throw new SystemException("Cannot get the list of nodes from the repository", e); } }
private void authorizeNodeCollectionOperation(ModelAuthorizationAction action, Collection<String> identifiers, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, SecurityViolationException, ExpressionEvaluationException, CommunicationException, ConfigurationException { if (securityEnforcer.isAuthorized(AuthorizationConstants.AUTZ_ALL_URL, null, AuthorizationParameters.EMPTY, null, task, parentResult)) { return; } for (String identifier : identifiers) { PrismObject<NodeType> existingObject; ObjectQuery q = ObjectQueryUtil.createNameQuery(NodeType.class, prismContext, identifier); List<PrismObject<NodeType>> nodes = cacheRepositoryService.searchObjects(NodeType.class, q, null, parentResult); if (nodes.isEmpty()) { throw new ObjectNotFoundException("Node with identifier '" + identifier + "' couldn't be found."); } else if (nodes.size() > 1) { throw new SystemException("Multiple nodes with identifier '" + identifier + "'"); } existingObject = nodes.get(0); securityEnforcer.authorize(action.getUrl(), null, AuthorizationParameters.Builder.buildObject(existingObject), null, task, parentResult); } }
ObjectQuery query = ObjectQueryUtil.createNameQuery(object); List<PrismObject<T>> foundObjects = repository.searchObjects(object.getCompileTimeClass(), query, null, result); if (foundObjects.size() == 1) { ObjectQuery query = ObjectQueryUtil.createNameQuery(object); List<PrismObject<T>> foundObjects = repository.searchObjects(object.getCompileTimeClass(), query, null, result); if (foundObjects.size() == 1) {
public <T extends ObjectType> void importSample(File sampleFile, Class<T> type, String objectName) throws FileNotFoundException, SchemaException { TestUtil.displayTestTitle(this, "Import sample "+sampleFile.getPath()); // GIVEN Task task = taskManager.createTaskInstance(); OperationResult result = new OperationResult(TestSampleImport.class.getName() + ".importSample"); result.addParam("file", sampleFile.getPath()); FileInputStream stream = new FileInputStream(sampleFile); // WHEN modelService.importObjectsFromStream(stream, MiscSchemaUtil.getDefaultImportOptions(), task, result); // THEN result.computeStatus(); display("Result after good import", result); TestUtil.assertSuccessOrWarning("Import has failed (result)", result,1); // ObjectQuery query = ObjectQuery.createObjectQuery(EqualsFilter.createEqual(type, prismContext, // ObjectType.F_NAME, PrismTestUtil.createPolyString(objectName))); // QueryType query = QueryUtil.createNameQuery(objectName); ObjectQuery query = ObjectQueryUtil.createNameQuery(objectName, prismContext); List<PrismObject<T>> objects = repositoryService.searchObjects(type, query, null, result); for (PrismObject<T> o : objects) { T object = o.asObjectable(); display("Found object",object); } assertEquals("Unexpected search result: "+objects,1,objects.size()); }
@Test public void test100GoodRefImport() throws Exception { final String TEST_NAME = "test100GoodRefImport"; TestUtil.displayTestTitle(this,TEST_NAME); // GIVEN Task task = taskManager.createTaskInstance(); OperationResult result = new OperationResult(AbstractImportTest.class.getName() + "." +TEST_NAME); FileInputStream stream = new FileInputStream(getFile(IMPORT_REF_FILE_NAME, false)); // WHEN modelService.importObjectsFromStream(stream, getLanguage(), getDefaultImportOptions(), task, result); // THEN result.computeStatus("Failed import."); display("Result after good import", result); TestUtil.assertSuccessOrWarning("Import has failed (result)", result, 2); // EqualsFilter equal = EqualsFilter.createEqual(UserType.F_NAME, UserType.class, PrismTestUtil.getPrismContext(), null, "jack"); // ObjectQuery query = ObjectQuery.createObjectQuery(equal); ObjectQuery query = ObjectQueryUtil.createNameQuery("jack", PrismTestUtil.getPrismContext()); List<PrismObject<UserType>> users = repositoryService.searchObjects(UserType.class, query, null, result); assertNotNull(users); assertEquals("Search returned unexpected results", 1, users.size()); UserType jack = users.get(0).asObjectable(); assertNotNull(jack); PrismAsserts.assertEqualsPolyString("wrong givenName", "Jack", jack.getGivenName()); PrismAsserts.assertEqualsPolyString("wrong familyName", "Sparrow", jack.getFamilyName()); PrismAsserts.assertEqualsPolyString("wrong fullName", "Cpt. Jack Sparrow", jack.getFullName()); }
private UserType searchUserByName(String name) throws Exception { // Document doc = DOMUtil.getDocument(); // Element nameElement = doc.createElementNS(SchemaConstants.C_NAME.getNamespaceURI(), // SchemaConstants.C_NAME.getLocalPart()); // nameElement.setTextContent(name); // Element filter = QueryUtil.createEqualFilter(doc, null, nameElement); // // QueryType query = new QueryType(); // query.setFilter(filter); ObjectQuery q = ObjectQueryUtil.createNameQuery(UserType.class, prismContext, name); QueryType query = prismContext.getQueryConverter().createQueryType(q); OperationResultType resultType = new OperationResultType(); Holder<OperationResultType> resultHolder = new Holder<>(resultType); Holder<ObjectListType> listHolder = new Holder<>(); assertNoRepoCache(); modelWeb.searchObjects(ObjectTypes.USER.getTypeQName(), query, null, listHolder, resultHolder); assertNoRepoCache(); ObjectListType objects = listHolder.value; TestUtil.assertSuccess("searchObjects has failed", resultHolder.value); AssertJUnit.assertEquals("User not found (or found too many)", 1, objects.getObject().size()); UserType user = (UserType) objects.getObject().get(0); AssertJUnit.assertEquals(user.getName(), PrismTestUtil.createPolyStringType(name)); return user; }
ObjectQuery query = ObjectQueryUtil.createNameQuery("guybrush", PrismTestUtil.getPrismContext());
ObjectQuery query = ObjectQueryUtil.createNameQuery(ELAINE_NAME, prismContext); List<PrismObject<UserType>> users = repositoryService.searchObjects(UserType.class, query, null, repoResult); assertEquals("Wrong number of Elaines", 1, users.size());