List of usage examples for java.util EnumSet of
public static <E extends Enum<E>> EnumSet<E> of(E e)
From source file:ch.cyberduck.core.Archive.java
/** * @param files Files//from w w w . java 2 s . c o m * @return Expanded filenames */ public List<Path> getExpanded(final List<Path> files) { final List<Path> expanded = new ArrayList<Path>(); for (Path file : files) { expanded.add(new Path(file.getParent(), StringUtils.remove(file.getName(), String.format(".%s", this.getIdentifier())), EnumSet.of(Path.Type.file))); } return expanded; }
From source file:ch.cyberduck.core.manta.MantaReadFeatureTest.java
@Test public void testReadRangeUnknownLength() throws Exception { final Path drive = new MantaDirectoryFeature(session).mkdir(randomDirectory(), "", new TransferStatus()); final Path test = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new MantaTouchFeature(session).touch(test, new TransferStatus()); final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random()); final byte[] content = RandomUtils.nextBytes(1000); final OutputStream out = local.getOutputStream(false); assertNotNull(out);/*from w w w . j a va 2 s . com*/ IOUtils.write(content, out); out.close(); new DefaultUploadFeature<Void>(new MantaWriteFeature(session)).upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), new TransferStatus().length(content.length), new DisabledConnectionCallback()); final TransferStatus status = new TransferStatus(); status.setLength(-1L); status.setAppend(true); status.setOffset(100L); final InputStream in = new MantaReadFeature(session).read(test, status, new DisabledConnectionCallback()); assertNotNull(in); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length - 100); new StreamCopier(status, status).transfer(in, buffer); final byte[] reference = new byte[content.length - 100]; System.arraycopy(content, 100, reference, 0, content.length - 100); assertArrayEquals(reference, buffer.toByteArray()); in.close(); final MantaDeleteFeature delete = new MantaDeleteFeature(session); delete.delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
From source file:io.lavagna.service.ProjectServiceTest.java
@Test public void testFindAllForUser() { Helper.createUser(userRepository, "test", "user-test"); User user = userRepository.findUserByName("test", "user-test"); projectService.create("test", "TEST", "desc"); Project project = projectService.findByShortName("TEST"); // empty because the user don't have the correct role READ Assert.assertTrue(projectService.findAllForUserWithPermissionInProject(user).isEmpty()); // empty, because the role is system wide and not attached to the // specific project Role role = new Role("HAS_READ"); permissionService.createRole(role);//from w w w. j a va2 s . com permissionService.updatePermissionsToRole(role, EnumSet.of(Permission.READ)); permissionService.assignRoleToUsers(role, Collections.singleton(user.getId())); Assert.assertEquals(EnumSet.of(Permission.READ), permissionService.findBasePermissionByUserId(user.getId())); Assert.assertEquals(0, projectService.findAllForUserWithPermissionInProject(user).size()); // Role projectRole = new Role("PROJECT_HAS_READ"); permissionService.createRoleInProjectId(projectRole, project.getId()); permissionService.updatePermissionsToRoleInProjectId(projectRole, EnumSet.of(Permission.READ), project.getId()); permissionService.assignRoleToUsersInProjectId(projectRole, Collections.singleton(user.getId()), project.getId()); Assert.assertEquals(1, projectService.findAllForUserWithPermissionInProject(user).size()); Assert.assertEquals("test", projectService.findAllForUserWithPermissionInProject(user).get(0).getName()); }
From source file:org.ulyssis.ipp.processor.Processor.java
/** * Restore the state from the database/* w w w . ja v a2s.co m*/ * * @return Whether we could restore from db, if false, we're starting from a clean slate */ private boolean restoreFromDb() { Connection connection = null; Snapshot oldSnapshot = this.snapshot; try { connection = Database.createConnection(EnumSet.of(READ_WRITE)); Optional<Snapshot> snapshot = Snapshot.loadLatest(connection); if (snapshot.isPresent()) { this.snapshot = snapshot.get(); connection.commit(); return true; } else { List<Event> events = Event.loadAll(connection); Snapshot snapshotBefore = this.snapshot; // Instant now = Instant.now(); // TODO: Handle future events later! for (Event event : events) { if (!event.isRemoved()/* && event.getTime().isBefore(now)*/) { // TODO: Future events later! this.snapshot = event.apply(this.snapshot); this.snapshot.save(connection); } } connection.commit(); return !Objects.equals(this.snapshot, snapshotBefore); } } catch (SQLException | IOException e) { LOG.error("An error occurred when restoring from database!", e); this.snapshot = oldSnapshot; try { if (connection != null) { connection.rollback(); } } catch (SQLException e2) { LOG.error("Error in rollback after previous error", e2); } return false; } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { LOG.error("Error while closing connection", e); } } } }
From source file:com.cloudera.impala.authorization.AuthorizationChecker.java
public boolean hasAccess(User user, PrivilegeRequest request) { Preconditions.checkNotNull(user);//ww w .j a va 2 s .c om Preconditions.checkNotNull(request); // If authorization is not enabled the user will always have access. If this is // an internal request, the user will always have permission. if (!config_.isEnabled() || user instanceof ImpalaInternalAdminUser) { return true; } EnumSet<org.apache.sentry.core.Action> actions = request.getPrivilege().getHiveActions(); List<Authorizable> authorizeables = Lists.newArrayList(); authorizeables.add(new org.apache.sentry.core.Server(config_.getServerName())); // If request.getAuthorizeable() is null, the request is for server-level permission. if (request.getAuthorizeable() != null) { authorizeables.addAll(request.getAuthorizeable().getHiveAuthorizeableHierarchy()); } // The Hive Access API does not currently provide a way to check if the user // has any privileges on a given resource. if (request.getPrivilege().getAnyOf()) { for (org.apache.sentry.core.Action action : actions) { if (provider_.hasAccess(new org.apache.sentry.core.Subject(user.getShortName()), authorizeables, EnumSet.of(action))) { return true; } } return false; } else if (request.getPrivilege() == Privilege.CREATE && authorizeables.size() > 1) { // CREATE on an object requires CREATE on the parent, // so don't check access on the object we're creating. authorizeables.remove(authorizeables.size() - 1); } return provider_.hasAccess(new org.apache.sentry.core.Subject(user.getShortName()), authorizeables, actions); }
From source file:io.apiman.manager.test.server.ManagerApiTestServer.java
/** * Configure the web application(s)./*from w w w . j a v a 2 s. c o m*/ * @param handlers * @throws Exception */ protected void addModulesToJetty(ContextHandlerCollection handlers) throws Exception { /* ************* * APIMan DT API * ************* */ ServletContextHandler apiManServer = new ServletContextHandler(ServletContextHandler.SESSIONS); apiManServer.setSecurityHandler(createSecurityHandler()); apiManServer.setContextPath("/apiman"); //$NON-NLS-1$ apiManServer.addEventListener(new Listener()); apiManServer.addEventListener(new BeanManagerResourceBindingListener()); apiManServer.addEventListener(new ResteasyBootstrap()); apiManServer.addFilter(DatabaseSeedFilter.class, "/db-seeder", EnumSet.of(DispatcherType.REQUEST)); //$NON-NLS-1$ apiManServer.addFilter(LocaleFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); //$NON-NLS-1$ apiManServer.addFilter(SimpleCorsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); //$NON-NLS-1$ apiManServer.addFilter(AuthenticationFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); //$NON-NLS-1$ apiManServer.addFilter(DefaultSecurityContextFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); //$NON-NLS-1$ ServletHolder resteasyServlet = new ServletHolder(new HttpServletDispatcher()); resteasyServlet.setInitParameter("javax.ws.rs.Application", JettyDtApiApplication.class.getName()); //$NON-NLS-1$ apiManServer.addServlet(resteasyServlet, "/*"); //$NON-NLS-1$ apiManServer.setInitParameter("resteasy.injector.factory", "org.jboss.resteasy.cdi.CdiInjectorFactory"); //$NON-NLS-1$ //$NON-NLS-2$ apiManServer.setInitParameter("resteasy.scan", "true"); //$NON-NLS-1$ //$NON-NLS-2$ apiManServer.setInitParameter("resteasy.servlet.mapping.prefix", ""); //$NON-NLS-1$ //$NON-NLS-2$ // Add the web contexts to jetty handlers.addHandler(apiManServer); /* ************* * Mock Gateway (to test publishing of Services from dt to rt) * ************* */ ServletContextHandler mockGatewayServer = new ServletContextHandler(ServletContextHandler.SESSIONS); mockGatewayServer.setSecurityHandler(createSecurityHandler()); mockGatewayServer.setContextPath("/mock-gateway"); //$NON-NLS-1$ ServletHolder mockGatewayServlet = new ServletHolder(new MockGatewayServlet()); mockGatewayServer.addServlet(mockGatewayServlet, "/*"); //$NON-NLS-1$ // Add the web contexts to jetty handlers.addHandler(mockGatewayServer); }
From source file:fr.xebia.extras.selma.codegen.MapperClassGenerator.java
private void openClassBlock(JavaWriter writer, String adapterName, String strippedTypeName) throws IOException { String[] interfaceName = new String[] { strippedTypeName }; String className = strippedTypeName; Set<Modifier> modifiers = EnumSet.of(PUBLIC); if (mapper.isAbstractClass()) { interfaceName = new String[] {}; } else {/*from w w w. ja v a2s.com*/ className = null; } if (mapper.isFinalMappers()) { modifiers = EnumSet.of(PUBLIC, FINAL); } writer.beginType(adapterName, "class", modifiers, className, interfaceName); }
From source file:ch.cyberduck.core.onedrive.OneDriveReadFeatureTest.java
@Test public void testReadRangeUnknownLength() throws Exception { final Path drive = new OneDriveHomeFinderFeature(session).find(); final Path test = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new OneDriveTouchFeature(session).touch(test, new TransferStatus()); final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random()); final byte[] content = RandomUtils.nextBytes(1000); final OutputStream out = local.getOutputStream(false); assertNotNull(out);//from w ww . ja va 2 s. c o m IOUtils.write(content, out); out.close(); new DefaultUploadFeature<Void>(new OneDriveWriteFeature(session)).upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), new TransferStatus().length(content.length), new DisabledConnectionCallback()); final TransferStatus status = new TransferStatus(); status.setLength(-1L); status.setAppend(true); status.setOffset(100L); final InputStream in = new OneDriveReadFeature(session).read(test, status, new DisabledConnectionCallback()); assertNotNull(in); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length - 100); new StreamCopier(status, status).transfer(in, buffer); final byte[] reference = new byte[content.length - 100]; System.arraycopy(content, 100, reference, 0, content.length - 100); assertArrayEquals(reference, buffer.toByteArray()); in.close(); new OneDriveDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
From source file:com.adguard.filter.rules.UrlFilterRule.java
/** * Checks request url against this filter rule. * Detects content type from the URL./*from w w w.j a v a2 s . c o m*/ * * @param requestUrl Request URL * @param thirdParty true for third-party request * @return true if request is filtered */ public boolean isFiltered(String requestUrl, boolean thirdParty) { return isFiltered(requestUrl, thirdParty, EnumSet.of(ContentType.detectContentType(requestUrl))); }
From source file:ch.cyberduck.core.nio.LocalWriteFeatureTest.java
@Test public void testAppend() throws Exception { final LocalSession session = new LocalSession( new Host(new LocalProtocol(), new LocalProtocol().getDefaultHostname())); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path workdir = new LocalHomeFinderFeature(session).find(); final Path test = new Path(workdir, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); assertFalse(new LocalWriteFeature(session).append(test, 0L, PathCache.empty()).append); new LocalTouchFeature(session).touch(test, new TransferStatus()); assertTrue(new LocalWriteFeature(session).append(test, 0L, PathCache.empty()).append); new LocalDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); }