protected boolean resourceCheckInListIds(IPResource resource, List<Long> resourceIds) { return resourceIds.stream() // .map(it -> resourceService.resourceFind(it).get()) // .filter(it -> resourceService.resourceEqualsPk(resource, it)) // .findAny().isPresent(); }
public void resourceDelete(Long resourceId) { if (resourceId == null) { throw new IllegalUpdateException("Cannot delete a resource without id"); } resourcesToDelete.add(resourceId); // Remove in add and update Optional<IPResource> resourceOptional = resourceService.resourceFind(resourceId); if (resourceOptional.isPresent()) { IPResource resource = resourceOptional.get(); resourcesToAdd.removeIf(it -> resourceService.resourceEqualsPk(resource, it)); } resourcesToUpdate.removeIf(it -> it.getA() == resourceId); }
protected void assertInfraConfigApps(String resourceName) { List<IPResource> resources = new ArrayList<>(); IPResourceService resourceService = getCommonServicesContext().getResourceService(); resources.add(resourceService.resourceFind(resourceService.createResourceQuery(Application.class) // .propertyEquals(Application.PROPERTY_NAME, "infra_login")).get()); resources.add(resourceService.resourceFind(resourceService.createResourceQuery(Application.class) // .propertyEquals(Application.PROPERTY_NAME, "infra_ui")).get()); resources.add(resourceService.resourceFind(resourceService.createResourceQuery(Website.class) // .propertyEquals(Website.PROPERTY_NAME, "infra_login")).get()); resources.add(resourceService.resourceFind(resourceService.createResourceQuery(Website.class) // .propertyEquals(Website.PROPERTY_NAME, "infra_ui")).get()); AssertTools.assertJsonComparison(resourceName, AbstractIPResourceServiceTest.class, resources); }
private UnixUser findByName(String name) { IPResourceService resourceService = getCommonServicesContext().getResourceService(); return resourceService.resourceFind(resourceService.createResourceQuery(UnixUser.class) // .propertyEquals(UnixUser.PROPERTY_NAME, name)) // .get(); }
protected void createUnixUserIfMissing(IPResourceService resourceService, ChangesContext changes) { Optional<UnixUser> unixUserOptional = resourceService.resourceFind(resourceService.createResourceQuery(UnixUser.class).propertyEquals(UnixUser.PROPERTY_NAME, UNIX_USER_REDIRECTION_NAME)); if (!unixUserOptional.isPresent()) { logger.info("Could not find the unix user {}. Will create it", UNIX_USER_REDIRECTION_NAME); UnixUser unixUser = new UnixUser(UnixUserAvailableIdHelper.getNextAvailableId(), UNIX_USER_REDIRECTION_NAME, "/home/" + UNIX_USER_REDIRECTION_NAME, null, null); changes.resourceAdd(unixUser); } }
Optional<UnixUser> unixUser = resourceService.resourceFind(resourceService.createResourceQuery(UnixUser.class) // .propertyEquals(UnixUser.PROPERTY_NAME, username)); if (unixUser.isPresent()) {
Optional<UnixUser> unixUser = resourceService.resourceFind(resourceService.createResourceQuery(UnixUser.class) // .propertyEquals(UnixUser.PROPERTY_NAME, username)); if (unixUser.isPresent()) {
Optional<UnixUser> unixUserOptional = resourceService.resourceFind(resourceService.createResourceQuery(UnixUser.class).propertyEquals(UnixUser.PROPERTY_NAME, unixUserName)); logger.info("Getting unix user {}. Is present: {}", unixUserName, unixUserOptional.isPresent()); if (!unixUserOptional.isPresent()) {
private void assertUnixUserNotExists(String name) { IPResourceService resourceService = getCommonServicesContext().getResourceService(); Assert.assertFalse(resourceService.resourceFind(resourceService.createResourceQuery(UnixUser.class) // .propertyEquals(UnixUser.PROPERTY_NAME, name)) // .isPresent()); }
Optional<SystemUnixUser> unixUser = resourceService.resourceFind(resourceService.createResourceQuery(SystemUnixUser.class) // .propertyEquals(UnixUser.PROPERTY_NAME, username)); if (unixUser.isPresent()) {
Optional<SystemUnixUser> unixUser = resourceService.resourceFind(resourceService.createResourceQuery(SystemUnixUser.class) // .propertyEquals(UnixUser.PROPERTY_NAME, username)); if (unixUser.isPresent()) {
@Test public void testQueryIds() { IPResourceService resourceService = getCommonServicesContext().getResourceService(); // Get the initial id Optional<JunitResource> junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .propertyContains(JunitResource.PROPERTY_SET_TEXTS, Arrays.asList("two"))// ); Assert.assertTrue(junitResourceOptional.isPresent()); long expectedId = junitResourceOptional.get().getInternalId(); // Get the resource junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .addIdEquals(expectedId) // ); Assert.assertTrue(junitResourceOptional.isPresent()); Assert.assertEquals((Long) expectedId, junitResourceOptional.get().getInternalId()); // Don't get it if not the right type Optional<DnsEntry> dnsEntryOptional = resourceService.resourceFind(resourceService.createResourceQuery(DnsEntry.class) // .addIdEquals(expectedId) // ); Assert.assertFalse(dnsEntryOptional.isPresent()); }
@Test public void testQueryIds() { IPResourceService resourceService = getCommonServicesContext().getResourceService(); // Get the initial id Optional<JunitResource> junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .propertyEquals(JunitResource.PROPERTY_SET_TEXTS, "two")// ); Assert.assertTrue(junitResourceOptional.isPresent()); long expectedId = junitResourceOptional.get().getInternalId(); // Get the resource junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .addIdEquals(expectedId) // ); Assert.assertTrue(junitResourceOptional.isPresent()); Assert.assertEquals((Long) expectedId, junitResourceOptional.get().getInternalId()); // Don't get it if not the right type Optional<DnsEntry> dnsEntryOptional = resourceService.resourceFind(resourceService.createResourceQuery(DnsEntry.class) // .addIdEquals(expectedId) // ); Assert.assertFalse(dnsEntryOptional.isPresent()); }
private FinalStateManagedResource createWebsite(String protocol, FinalStateManagedResourcesUpdateEventHandlerContext<UrlRedirection> context, IPResourceService resourceService, String domainName, List<Machine> machines) { Website website = new Website(protocol + " Redirection of " + domainName); FinalStateManagedResource websiteFinalResource = new FinalStateManagedResource(); websiteFinalResource.setManagedResource(website); context.addManagedResources(websiteFinalResource); website.getDomainNames().add(domainName); website.setHttps("HTTPS".equals(protocol)); websiteFinalResource.addManagedLinksToType(LinkTypeConstants.POINTS_TO, LinkTypeConstants.INSTALLED_ON, LinkTypeConstants.USES); machines.forEach(machine -> { // Machine websiteFinalResource.addLinkTo(LinkTypeConstants.INSTALLED_ON, machine); // Applications String applicationName = "infra_url_redirection_" + protocol.toLowerCase() + "-" + machine.getName().replaceAll("\\.", "_"); logger.info("Getting application {}", applicationName); Optional<Application> application = resourceService.resourceFind(resourceService.createResourceQuery(Application.class) // .propertyEquals(Application.PROPERTY_NAME, applicationName) // ); if (!application.isPresent()) { logger.info("Application {} does not exist for now. Skipping", applicationName); return; } websiteFinalResource.addLinkTo(LinkTypeConstants.POINTS_TO, application.get()); }); return websiteFinalResource; }
@Test public void testQueryEditorName() { IPResourceService resourceService = getCommonServicesContext().getResourceService(); InternalChangeService internalChangeService = getInternalServicesContext().getInternalChangeService(); // Get the initial id Optional<JunitResource> junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .propertyEquals(JunitResource.PROPERTY_SET_TEXTS, "two")// ); Assert.assertTrue(junitResourceOptional.isPresent()); long expectedId = junitResourceOptional.get().getInternalId(); // Modify its editor JunitResource resource = junitResourceOptional.get(); ChangesContext changes = new ChangesContext(); resource.setResourceEditorName("junit"); changes.getResourcesToUpdate().add(new Tuple2<>(expectedId, resource)); internalChangeService.changesExecute(changes); // Get the resource junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .addEditorEquals("junit") // ); Assert.assertTrue(junitResourceOptional.isPresent()); Assert.assertEquals((Long) expectedId, junitResourceOptional.get().getInternalId()); // Don't get the resource if wrong editor junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .addEditorEquals("not junit") // ); Assert.assertFalse(junitResourceOptional.isPresent()); }
@Test public void testQueryOne_failMoreThanOne() { thrown.expectMessage("There are more than one item matching the query"); IPResourceService resourceService = getCommonServicesContext().getResourceService(); resourceService.resourceFind( // resourceService.createResourceQuery(JunitResource.class) // .propertyEquals(JunitResource.PROPERTY_TEXT, "www.example.com") // ); }
Optional<? extends IPResource> linkedResourceOptional = servicesCtx.getResourceService().resourceFind( //
@Test public void testQueryOne_failMoreThanOne() { thrown.expectMessage("There are more than one item matching the query"); IPResourceService resourceService = getCommonServicesContext().getResourceService(); resourceService.resourceFind( // resourceService.createResourceQuery(JunitResource.class) // .propertyEquals(JunitResource.PROPERTY_TEXT, "www.example.com") // ); }
@Test public void testQueryEditorName() { IPResourceService resourceService = getCommonServicesContext().getResourceService(); InternalChangeService internalChangeService = getInternalServicesContext().getInternalChangeService(); // Get the initial id Optional<JunitResource> junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .propertyContains(JunitResource.PROPERTY_SET_TEXTS, Arrays.asList("two"))// ); Assert.assertTrue(junitResourceOptional.isPresent()); long expectedId = junitResourceOptional.get().getInternalId(); // Modify its editor JunitResource resource = junitResourceOptional.get(); ChangesContext changes = new ChangesContext(getCommonServicesContext().getResourceService()); resource.setResourceEditorName("junit"); changes.resourceUpdate(expectedId, resource); internalChangeService.changesExecute(changes); // Get the resource junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .addEditorEquals("junit") // ); Assert.assertTrue(junitResourceOptional.isPresent()); Assert.assertEquals((Long) expectedId, junitResourceOptional.get().getInternalId()); // Don't get the resource if wrong editor junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .addEditorEquals("not junit") // ); Assert.assertFalse(junitResourceOptional.isPresent()); }
resource = resourceEditor.getForResourceType().newInstance(); } else { resource = (T) getCommonServicesContext().getResourceService().resourceFind(internalId).get();