Example usage for java.util EnumSet allOf

List of usage examples for java.util EnumSet allOf

Introduction

In this page you can find the example usage for java.util EnumSet allOf.

Prototype

public static <E extends Enum<E>> EnumSet<E> allOf(Class<E> elementType) 

Source Link

Document

Creates an enum set containing all of the elements in the specified element type.

Usage

From source file:org.apache.accumulo.test.proxy.SimpleProxyBase.java

@Test(expected = AccumuloSecurityException.class, timeout = 5000)
public void removeNamespaceIteratorLoginFailure() throws Exception {
    client.removeNamespaceIterator(badLogin, namespaceName, "DebugTheThings",
            EnumSet.allOf(IteratorScope.class));
}

From source file:org.apache.accumulo.proxy.SimpleTest.java

@Test(timeout = 10000)
public void testInstanceOperations() throws Exception {
    int tservers = 0;
    for (String tserver : client.getTabletServers(creds)) {
        client.pingTabletServer(creds, tserver);
        tservers++;/*w  ww  .  j ava  2  s .c  o  m*/
    }
    assertTrue(tservers > 0);

    // get something we know is in the site config
    Map<String, String> cfg = client.getSiteConfiguration(creds);
    assertTrue(cfg.get("instance.dfs.dir").startsWith(folder.getRoot().toString()));

    // set a property in zookeeper
    client.setProperty(creds, "table.split.threshold", "500M");

    // check that we can read it
    for (int i = 0; i < 5; i++) {
        cfg = client.getSystemConfiguration(creds);
        if ("500M".equals(cfg.get("table.split.threshold")))
            break;
        UtilWaitThread.sleep(200);
    }
    assertEquals("500M", cfg.get("table.split.threshold"));

    // unset the setting, check that it's not what it was
    client.removeProperty(creds, "table.split.threshold");
    for (int i = 0; i < 5; i++) {
        cfg = client.getSystemConfiguration(creds);
        if (!"500M".equals(cfg.get("table.split.threshold")))
            break;
        UtilWaitThread.sleep(200);
    }
    assertNotEquals("500M", cfg.get("table.split.threshold"));

    // try to load some classes via the proxy
    assertTrue(client.testClassLoad(creds, DevNull.class.getName(), SortedKeyValueIterator.class.getName()));
    assertFalse(client.testClassLoad(creds, "foo.bar", SortedKeyValueIterator.class.getName()));

    // create a table that's very slow, so we can look for scans/compactions
    client.createTable(creds, "slow", true, TimeType.MILLIS);
    IteratorSetting setting = new IteratorSetting(100, "slow", SlowIterator.class.getName(),
            Collections.singletonMap("sleepTime", "200"));
    client.attachIterator(creds, "slow", setting, EnumSet.allOf(IteratorScope.class));
    client.updateAndFlush(creds, "slow", mutation("row", "cf", "cq", "value"));
    client.updateAndFlush(creds, "slow", mutation("row2", "cf", "cq", "value"));
    client.updateAndFlush(creds, "slow", mutation("row3", "cf", "cq", "value"));
    client.updateAndFlush(creds, "slow", mutation("row4", "cf", "cq", "value"));

    // scan
    Thread t = new Thread() {
        @Override
        public void run() {
            String scanner;
            try {
                Client client2 = new TestProxyClient("localhost", proxyPort, protocolClass.newInstance())
                        .proxy();
                scanner = client2.createScanner(creds, "slow", null);
                client2.nextK(scanner, 10);
                client2.closeScanner(scanner);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    t.start();
    // look for the scan
    List<ActiveScan> scans = Collections.emptyList();
    loop: for (int i = 0; i < 100; i++) {
        for (String tserver : client.getTabletServers(creds)) {
            scans = client.getActiveScans(creds, tserver);
            if (!scans.isEmpty())
                break loop;
            UtilWaitThread.sleep(10);
        }
    }
    t.join();
    assertFalse(scans.isEmpty());
    ActiveScan scan = scans.get(0);
    assertEquals("root", scan.getUser());
    assertTrue(ScanState.RUNNING.equals(scan.getState()) || ScanState.QUEUED.equals(scan.getState()));
    assertEquals(ScanType.SINGLE, scan.getType());
    assertEquals("slow", scan.getTable());
    Map<String, String> map = client.tableIdMap(creds);
    assertEquals(map.get("slow"), scan.getExtent().tableId);
    assertTrue(scan.getExtent().endRow == null);
    assertTrue(scan.getExtent().prevEndRow == null);

    // start a compaction
    t = new Thread() {
        @Override
        public void run() {
            try {
                Client client2 = new TestProxyClient("localhost", proxyPort, protocolClass.newInstance())
                        .proxy();
                client2.compactTable(creds, "slow", null, null, null, true, true);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    t.start();

    // try to catch it in the act
    List<ActiveCompaction> compactions = Collections.emptyList();
    loop2: for (int i = 0; i < 100; i++) {
        for (String tserver : client.getTabletServers(creds)) {
            compactions = client.getActiveCompactions(creds, tserver);
            if (!compactions.isEmpty())
                break loop2;
        }
        UtilWaitThread.sleep(10);
    }
    t.join();
    // verify the compaction information
    assertFalse(compactions.isEmpty());
    ActiveCompaction c = compactions.get(0);
    assertEquals(map.get("slow"), c.getExtent().tableId);
    assertTrue(c.inputFiles.isEmpty());
    assertEquals(CompactionType.MINOR, c.getType());
    assertEquals(CompactionReason.USER, c.getReason());
    assertEquals("", c.localityGroup);
    assertTrue(c.outputFile.contains("default_tablet"));
}

From source file:org.totschnig.myexpenses.util.Utils.java

public static <E extends Enum<E>> String joinEnum(Class<E> enumClass) {
    String result = "";
    Iterator<E> iterator = EnumSet.allOf(enumClass).iterator();
    while (iterator.hasNext()) {
        result += "'" + iterator.next().name() + "'";
        if (iterator.hasNext())
            result += ",";
    }/*from   w  w  w  .  ja  va2s.  co  m*/
    return result;
}

From source file:org.apache.accumulo.test.proxy.SimpleProxyBase.java

@Test(expected = AccumuloSecurityException.class, timeout = 5000)
public void checkNamespaceIteratorConflictsLoginFailure() throws Exception {
    IteratorSetting setting = new IteratorSetting(100, "DebugTheThings", DebugIterator.class.getName(),
            Collections.<String, String>emptyMap());
    client.checkNamespaceIteratorConflicts(badLogin, namespaceName, setting,
            EnumSet.allOf(IteratorScope.class));
}

From source file:org.silverpeas.migration.jcr.service.repository.DocumentRepositoryTest.java

/**
 * Test of listForeignIdsByType method, of class DocumentRepository.
 *///from w  w w  .  ja  v  a  2  s.c om
@Test
public void listForeignIdsByType() throws Exception {
    new JcrDocumentRepositoryTest() {
        @Override
        public void run(final Session session) throws Exception {
            Set<String> createdIds = new HashSet<String>();
            // No WYSIWYG content exists
            Set<String> foreignIds = getDocumentRepository().listForeignIdsByType(session, instanceId, wysiwyg);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(0));
            foreignIds = getDocumentRepository().listForeignIdsByType(session, instanceId, attachment);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(0));

            // Creating an FR "attachment" content.
            String createdUuid = createAttachmentForTest(
                    defaultDocumentBuilder("fId_1").setDocumentType(attachment), defaultFRContentBuilder(),
                    "fId_1_fr").getId();
            createdIds.add(createdUuid);
            SimpleDocument enDocument = getDocumentById(createdUuid, "en");
            assertThat(enDocument, notNullValue());
            assertThat(enDocument.getAttachment(), nullValue());
            SimpleDocument frDocument = getDocumentById(createdUuid, "fr");
            assertThat(frDocument, notNullValue());
            assertThat(frDocument.getAttachment(), notNullValue());
            assertThat(frDocument.getDocumentType(), is(attachment));

            // Updating attachment with EN content.
            setEnData(frDocument);
            updateAttachmentForTest(frDocument, "en", "fId_1_en");
            createdIds.add(frDocument.getId());

            // Vrifying the attachment exists into both of tested languages.
            enDocument = getDocumentById(createdUuid, "en");
            assertThat(enDocument, notNullValue());
            assertThat(enDocument.getAttachment(), notNullValue());
            assertThat(enDocument.getDocumentType(), is(attachment));
            checkEnglishSimpleDocument(enDocument);
            frDocument = getDocumentById(createdUuid, "fr");
            assertThat(frDocument, notNullValue());
            assertThat(frDocument.getAttachment(), notNullValue());
            assertThat(frDocument.getDocumentType(), is(attachment));
            checkFrenchSimpleDocument(frDocument);

            // No WYSIWYG : that is what it is expected
            foreignIds = getDocumentRepository().listForeignIdsByType(session, instanceId, wysiwyg);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(0));
            foreignIds = getDocumentRepository().listForeignIdsByType(session, instanceId, attachment);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(1));
            assertThat(foreignIds, contains("fId_1"));

            // Adding several documents, but no WYSIWYG
            Set<DocumentType> documentTypes = EnumSet.allOf(DocumentType.class);
            documentTypes.remove(DocumentType.wysiwyg);
            int id = 2;
            for (DocumentType documentType : documentTypes) {
                createdIds.add(createAttachmentForTest(
                        defaultDocumentBuilder("fId_" + id).setDocumentType(documentType),
                        defaultFRContentBuilder().setFilename("fId_" + id + "_wysiwyg_en.txt"),
                        "fId_" + id + "_fr").getId());
                id++;
            }

            // No WYSIWYG : that is what it is expected
            foreignIds = getDocumentRepository().listForeignIdsByType(session, instanceId, wysiwyg);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(0));
            foreignIds = getDocumentRepository().listForeignIdsByType(session, instanceId, attachment);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(2));

            // Number of expected created documents
            int nbDocuments = 1 + (DocumentType.values().length - 1);
            assertThat(createdIds.size(), is(nbDocuments));

            // Adding the first WYSIWYG EN content
            SimpleDocument createdDocument = createAttachmentForTest(
                    defaultDocumentBuilder("fId_26").setDocumentType(wysiwyg), defaultENContentBuilder(),
                    "fId_26_en");
            createdIds.add(createdDocument.getId());
            createAttachmentForTest(defaultDocumentBuilder("otherKmelia38", "fId_26").setDocumentType(wysiwyg),
                    defaultENContentBuilder(), "fId_26_en");

            // One wrong WYSIWYG base name
            foreignIds = getDocumentRepository().listForeignIdsByType(session, instanceId, wysiwyg);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(1));
            assertThat(foreignIds, contains("fId_26"));
            foreignIds = getDocumentRepository().listForeignIdsByType(session, "otherKmelia38", wysiwyg);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(1));
            assertThat(foreignIds, contains("fId_26"));

            // Updating wysiwyg file name
            createdDocument.setFilename("fId_26_wysiwyg_en.txt");
            updateAttachmentForTest(createdDocument);

            // One WYSIWYG base name
            foreignIds = getDocumentRepository().listForeignIdsByType(session, instanceId, wysiwyg);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(1));
            assertThat(foreignIds, contains("fId_26"));
            foreignIds = getDocumentRepository().listForeignIdsByType(session, "otherKmelia38", wysiwyg);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(1));
            assertThat(foreignIds, contains("fId_26"));

            // Adding the FR content to the first WYSIWYG document
            enDocument = getDocumentById(createdDocument.getId(), "en");
            setFrData(enDocument);
            enDocument.setFilename("fId_26_wysiwyg_fr.txt");
            updateAttachmentForTest(enDocument, "fr", "fId_26_fr");
            createdIds.add(enDocument.getId());

            // One WYSIWYG on one Component
            foreignIds = getDocumentRepository().listForeignIdsByType(session, instanceId, wysiwyg);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(1));
            assertThat(foreignIds, contains("fId_26"));
            foreignIds = getDocumentRepository().listForeignIdsByType(session, "otherKmelia38", wysiwyg);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(1));
            assertThat(foreignIds, contains("fId_26"));

            // Adding the second WYSIWYG document (on same component)
            SimpleDocument secondCreatedDocument = createAttachmentForTest(
                    defaultDocumentBuilder("fId_27").setDocumentType(wysiwyg),
                    defaultFRContentBuilder().setFilename("fId_27_wysiwyg_fr.txt"), "fId_27_fr");
            createdIds.add(secondCreatedDocument.getId());

            // Two WYSIWYG on one Component
            foreignIds = getDocumentRepository().listForeignIdsByType(session, instanceId, wysiwyg);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(2));
            assertThat(foreignIds, containsInAnyOrder("fId_26", "fId_27"));
            foreignIds = getDocumentRepository().listForeignIdsByType(session, "otherKmelia38", wysiwyg);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(1));
            assertThat(foreignIds, contains("fId_26"));

            // Updating wysiwyg file name
            setEnData(secondCreatedDocument);
            secondCreatedDocument.setFilename(secondCreatedDocument.getFilename());
            updateAttachmentForTest(secondCreatedDocument, "en", "fId_27_en");

            // Two WYSIWYG (each one in two languages) on one Component
            foreignIds = getDocumentRepository().listForeignIdsByType(session, instanceId, wysiwyg);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(2));
            assertThat(foreignIds, containsInAnyOrder("fId_26", "fId_27"));
            foreignIds = getDocumentRepository().listForeignIdsByType(session, "otherKmelia38", wysiwyg);
            assertThat(foreignIds, notNullValue());
            assertThat(foreignIds, hasSize(1));
            assertThat(foreignIds, contains("fId_26"));

            assertThat(createdIds, hasSize(nbDocuments + 2));
        }
    }.execute();
}

From source file:org.apache.accumulo.proxy.SimpleProxyIT.java

@Test(timeout = 10000)
public void testInstanceOperations() throws Exception {
    int tservers = 0;
    for (String tserver : client.getTabletServers(creds)) {
        client.pingTabletServer(creds, tserver);
        tservers++;/*from   w ww.  j  a  v  a  2s .  co  m*/
    }
    assertTrue(tservers > 0);

    // get something we know is in the site config
    Map<String, String> cfg = client.getSiteConfiguration(creds);
    assertTrue(cfg.get("instance.dfs.dir").startsWith(macTestFolder.getPath()));

    // set a property in zookeeper
    client.setProperty(creds, "table.split.threshold", "500M");

    // check that we can read it
    for (int i = 0; i < 5; i++) {
        cfg = client.getSystemConfiguration(creds);
        if ("500M".equals(cfg.get("table.split.threshold")))
            break;
        UtilWaitThread.sleep(200);
    }
    assertEquals("500M", cfg.get("table.split.threshold"));

    // unset the setting, check that it's not what it was
    client.removeProperty(creds, "table.split.threshold");
    for (int i = 0; i < 5; i++) {
        cfg = client.getSystemConfiguration(creds);
        if (!"500M".equals(cfg.get("table.split.threshold")))
            break;
        UtilWaitThread.sleep(200);
    }
    assertNotEquals("500M", cfg.get("table.split.threshold"));

    // try to load some classes via the proxy
    assertTrue(client.testClassLoad(creds, DevNull.class.getName(), SortedKeyValueIterator.class.getName()));
    assertFalse(client.testClassLoad(creds, "foo.bar", SortedKeyValueIterator.class.getName()));

    // create a table that's very slow, so we can look for scans/compactions
    client.createTable(creds, "slow", true, TimeType.MILLIS);
    IteratorSetting setting = new IteratorSetting(100, "slow", SlowIterator.class.getName(),
            Collections.singletonMap("sleepTime", "200"));
    client.attachIterator(creds, "slow", setting, EnumSet.allOf(IteratorScope.class));
    client.updateAndFlush(creds, "slow", mutation("row", "cf", "cq", "value"));
    client.updateAndFlush(creds, "slow", mutation("row2", "cf", "cq", "value"));
    client.updateAndFlush(creds, "slow", mutation("row3", "cf", "cq", "value"));
    client.updateAndFlush(creds, "slow", mutation("row4", "cf", "cq", "value"));

    // scan
    Thread t = new Thread() {
        @Override
        public void run() {
            String scanner;
            try {
                Client client2 = new TestProxyClient("localhost", proxyPort, protocolClass.newInstance())
                        .proxy();
                scanner = client2.createScanner(creds, "slow", null);
                client2.nextK(scanner, 10);
                client2.closeScanner(scanner);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    t.start();
    // look for the scan
    List<ActiveScan> scans = Collections.emptyList();
    loop: for (int i = 0; i < 100; i++) {
        for (String tserver : client.getTabletServers(creds)) {
            scans = client.getActiveScans(creds, tserver);
            if (!scans.isEmpty())
                break loop;
            UtilWaitThread.sleep(10);
        }
    }
    t.join();
    assertFalse(scans.isEmpty());
    ActiveScan scan = scans.get(0);
    assertEquals("root", scan.getUser());
    assertTrue(ScanState.RUNNING.equals(scan.getState()) || ScanState.QUEUED.equals(scan.getState()));
    assertEquals(ScanType.SINGLE, scan.getType());
    assertEquals("slow", scan.getTable());
    Map<String, String> map = client.tableIdMap(creds);
    assertEquals(map.get("slow"), scan.getExtent().tableId);
    assertTrue(scan.getExtent().endRow == null);
    assertTrue(scan.getExtent().prevEndRow == null);

    // start a compaction
    t = new Thread() {
        @Override
        public void run() {
            try {
                Client client2 = new TestProxyClient("localhost", proxyPort, protocolClass.newInstance())
                        .proxy();
                client2.compactTable(creds, "slow", null, null, null, true, true);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    t.start();

    // try to catch it in the act
    List<ActiveCompaction> compactions = Collections.emptyList();
    loop2: for (int i = 0; i < 100; i++) {
        for (String tserver : client.getTabletServers(creds)) {
            compactions = client.getActiveCompactions(creds, tserver);
            if (!compactions.isEmpty())
                break loop2;
        }
        UtilWaitThread.sleep(10);
    }
    t.join();
    // verify the compaction information
    assertFalse(compactions.isEmpty());
    ActiveCompaction c = compactions.get(0);
    assertEquals(map.get("slow"), c.getExtent().tableId);
    assertTrue(c.inputFiles.isEmpty());
    assertEquals(CompactionType.MINOR, c.getType());
    assertEquals(CompactionReason.USER, c.getReason());
    assertEquals("", c.localityGroup);
    assertTrue(c.outputFile.contains("default_tablet"));
}

From source file:org.wso2.carbon.bpel.core.ode.integration.mgt.services.InstanceManagementServiceSkeleton.java

/**
 * Delete Instances that matches the filter
 *
 * @param filter Instance filter// w ww.  ja va 2 s. c  om
 * @return Number of instances deleted
 * @throws InstanceManagementException If the filter is invalid or an exception occurred during
 *                                     instance deletion
 */
public int deleteInstances(String filter, final boolean deleteMessageExchanges)
        throws InstanceManagementException {

    String tFilter = filter;

    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    TenantProcessStoreImpl tenantProcessStore = (TenantProcessStoreImpl) bpelServer.getMultiTenantProcessStore()
            .getTenantsProcessStore(tenantId);

    if (isInvalidFilter(tFilter)) {
        String errMsg = "Invalid instance filter: " + tFilter;
        log.error(errMsg);
        throw new InstanceManagementException(errMsg);
    }

    if (!isSecureFilter(new InstanceFilter(tFilter), tenantProcessStore.getProcessConfigMap().keySet())) {
        String errMsg = "Instance deletion operation not permitted due to insecure filter: " + tFilter;
        log.error(errMsg);
        throw new InstanceManagementException(errMsg);
    }

    if (!tFilter.contains(" pid=")) {
        tFilter = tFilter + getTenantsProcessList(tenantProcessStore.getProcessConfigMap().keySet());
    }

    final InstanceFilter instanceFilter = new InstanceFilter(tFilter);

    final List<Long> ret = new LinkedList<Long>();
    try {
        final int deletionBatchSize = BPELServerImpl.getInstance().getBpelServerConfiguration()
                .getBpelInstanceDeletionLimit();
        dbexec(new BpelDatabase.Callable<Object>() {
            public Object run(BpelDAOConnection conn) throws IllegalAccessException {
                Collection<ProcessInstanceDAO> instances = conn.instanceQuery(instanceFilter);

                // Doing this to avoid any half done operation.
                // For example if filter returns set of instance which are not owned by this tenant we should
                // not delete other instances also.
                for (ProcessInstanceDAO instance : instances) {
                    isOperationIsValidForTheCurrentTenant(instance.getProcess().getProcessId());
                }

                int count = 1;
                for (ProcessInstanceDAO instance : instances) {
                    instance.delete(EnumSet.allOf(ProcessConf.CLEANUP_CATEGORY.class), deleteMessageExchanges);
                    ret.add(instance.getInstanceId());
                    count++;
                    //limiting number of instances that can be deleted to avoid timeout exceptions
                    if (count > deletionBatchSize) {
                        break;
                    }
                }
                return null;
            }
        });
    } catch (Exception e) {
        String errMsg = "Exception during instance deletion. Filter: " + instanceFilter.toString();
        log.error(errMsg, e);
        throw new InstanceManagementException(errMsg, e);
    }

    return ret.size();
}

From source file:com.gtwm.pb.servlets.AppController.java

/**
 * The main control function, called for every HTTP GET or POST request.
 * Basically performs three functions://from   w  ww  .  j a v  a  2  s  . c om
 * 
 * 1) Sets any session variables posted from the user interface, if any
 * 
 * 2) Performs any actions requested by the UI, if any
 * 
 * 3) Parses and returns the template requested by the UI
 */
public Template handleRequest(HttpServletRequest request, HttpServletResponse response, Context context) {
    // Start timing request
    long handleRequestStartTime = System.currentTimeMillis();
    // Cache multipart form data so don't have to reparse it all the time
    List<FileItem> multipartItems = ServletUtilMethods.getMultipartItems(request);
    logger.debug("Request: " + ServletUtilMethods.getRequestQuery(request));
    ResponseReturnType returnType = setReturnType(request, response, multipartItems);
    response.setCharacterEncoding("ISO-8859-1");
    HttpSession session = request.getSession();
    SessionDataInfo sessionData = (SessionDataInfo) session.getAttribute("com.gtwm.pb.servlets.sessionData");
    if (sessionData == null) {
        try {
            // Set up a session for a newly logged in user
            sessionData = new SessionData(this.databaseDefn, this.relationalDataSource, request);
        } catch (SQLException sqlex) {
            ServletUtilMethods.logException(sqlex, request, "SQL error creating session data object: " + sqlex);
            sessionData = new SessionData();
        } catch (AgileBaseException pbex) {
            ServletUtilMethods.logException(pbex, request, "Error creating session data object: " + pbex);
            sessionData = new SessionData();
        }
        // Set session cookie expiry date
        // String id = request.getSession().getId();
        // long expireTimestamp = System.currentTimeMillis() + (12 * 60 * 60
        // * 1000); // 12 hours ahead
        // String expireDate = new
        // SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z").format(new
        // Date(expireTimestamp));
        // response.setHeader("Set-Cookie",
        // String.format("JSESSIONID=%s;Expires=%s;Path=/agileBase", id,
        // expireDate));
    }
    String templateName = ServletUtilMethods.getParameter(request, "return", multipartItems);
    try {
        carryOutSessionActions(request, sessionData, this.databaseDefn, context, session, multipartItems);
    } catch (AgileBaseException pbex) {
        ServletUtilMethods.logException(pbex, request, "Error setting session data");
        if (returnType.equals(ResponseReturnType.XML)) {
            return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData,
                    pbex, multipartItems);
        }
    } catch (NumberFormatException nfex) {
        ServletUtilMethods.logException(nfex, request, "Non-numeric value specified for numeric parameter");
        if (returnType.equals(ResponseReturnType.XML)) {
            return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData,
                    nfex, multipartItems);
        }
    } catch (RuntimeException rtex) {
        ServletUtilMethods.logException(rtex, request, "Runtime error setting session data");
        if (returnType.equals(ResponseReturnType.XML)) {
            return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData,
                    rtex, multipartItems);
        }
    } catch (SQLException sqlex) {
        ServletUtilMethods.logException(sqlex, request, "SQL error setting session data");
        // override to return the error template
        templateName = "report_error";
        return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData, sqlex,
                multipartItems);
    } catch (Exception ex) {
        ServletUtilMethods.logException(ex, request, "General error setting session data");
        if (returnType.equals(ResponseReturnType.XML)) {
            return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData, ex,
                    multipartItems);
        } else {
            // override to return the error template
            templateName = "report_error";
            return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData, ex,
                    multipartItems);
        }
    }
    // Use StringBuffer to get a mutable string that can be altered by
    // carryOutAppActions
    StringBuffer appActionName = new StringBuffer("");
    try {
        carryOutAppActions(request, sessionData, this.databaseDefn, multipartItems, appActionName);
    } catch (MissingParametersException mpex) {
        ServletUtilMethods.logException(mpex, request,
                "Required parameters missing for action " + appActionName);
        return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData, mpex,
                multipartItems);
    } catch (DisallowedException dex) {
        ServletUtilMethods.logException(dex, request, "No privileges to perform action " + appActionName);
        return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData, dex,
                multipartItems);
    } catch (SQLException sqlex) {
        ServletUtilMethods.logException(sqlex, request,
                "Error accessing relational database while performing action" + appActionName);
        return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData, sqlex,
                multipartItems);
    } catch (ObjectNotFoundException onfex) {
        ServletUtilMethods.logException(onfex, request,
                "An object mis-referenced while performing action " + appActionName);
        return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData, onfex,
                multipartItems);
    } catch (InputRecordException irex) {
        ServletUtilMethods.logException(irex, request, "Error saving data during " + appActionName);
        return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData, irex,
                multipartItems);
    } catch (Exception ex) {
        ServletUtilMethods.logException(ex, request, "General error performing action " + appActionName);
        return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData, ex,
                multipartItems);
    }
    // Set any new values for the session variables after carrying out main
    // app actions
    EnumSet<SessionAction> sessionActions = EnumSet.allOf(SessionAction.class);
    try {
        carryOutPostSessionActions(request, sessionData, this.databaseDefn, sessionActions);
    } catch (ObjectNotFoundException onfex) {
        ServletUtilMethods.logException(onfex, request, "Error setting session data");
        if (returnType.equals(ResponseReturnType.XML)) {
            return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData,
                    onfex, multipartItems);
        }
    } catch (NumberFormatException nfex) {
        ServletUtilMethods.logException(nfex, request, "Non-numeric value specified for numeric parameter");
        if (returnType.equals(ResponseReturnType.XML)) {
            return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData,
                    nfex, multipartItems);
        }
    } catch (MissingParametersException mpex) {
        ServletUtilMethods.logException(mpex, request, "Error setting session data");
        if (returnType.equals(ResponseReturnType.XML)) {
            return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData,
                    mpex, multipartItems);
        }
    } catch (RuntimeException rtex) {
        ServletUtilMethods.logException(rtex, request, "Runtime error setting session data");
        if (returnType.equals(ResponseReturnType.XML)) {
            return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData,
                    rtex, multipartItems);
        }
    } catch (Exception ex) {
        ServletUtilMethods.logException(ex, request, "General error setting session data");
        if (returnType.equals(ResponseReturnType.XML)) {
            return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData, ex,
                    multipartItems);
        }
    }
    // Log long request times - doesn't include template rendering time: see
    // mergeTemplate for those
    float secondsToHandleRequest = (System.currentTimeMillis() - handleRequestStartTime) / ((float) 1000);
    if (secondsToHandleRequest > AppProperties.longProcessingTime) {
        String warnMessage = "Long server request processing time of " + String.valueOf(secondsToHandleRequest)
                + " seconds for URL " + ServletUtilMethods.getRequestQuery(request) + "\r\n";
        warnMessage += "Logged in user: " + request.getRemoteUser();
        logger.warn(warnMessage);
    }
    // Don't do HibernateUtil.closeSession() here, leave it open for the
    // view to display
    // in mergeTemplate()
    // Create ViewMethods object and return the requested template
    return getUserInterfaceTemplate(request, response, templateName, context, session, sessionData, null,
            multipartItems);
}

From source file:org.apache.accumulo.test.proxy.SimpleProxyBase.java

@Test
public void tableNotFound() throws Exception {
    final String doesNotExist = "doesNotExists";
    try {//from ww w .j a va2s . c om
        client.addConstraint(creds, doesNotExist, NumericValueConstraint.class.getName());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.addSplits(creds, doesNotExist, Collections.<ByteBuffer>emptySet());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    final IteratorSetting setting = new IteratorSetting(100, "slow", SlowIterator.class.getName(),
            Collections.singletonMap("sleepTime", "200"));
    try {
        client.attachIterator(creds, doesNotExist, setting, EnumSet.allOf(IteratorScope.class));
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.cancelCompaction(creds, doesNotExist);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.checkIteratorConflicts(creds, doesNotExist, setting, EnumSet.allOf(IteratorScope.class));
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.clearLocatorCache(creds, doesNotExist);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        final String TABLE_TEST = getUniqueNames(1)[0];
        client.cloneTable(creds, doesNotExist, TABLE_TEST, false, null, null);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.compactTable(creds, doesNotExist, null, null, null, true, false, null);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.createBatchScanner(creds, doesNotExist, new BatchScanOptions());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.createScanner(creds, doesNotExist, new ScanOptions());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.createWriter(creds, doesNotExist, new WriterOptions());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.deleteRows(creds, doesNotExist, null, null);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.deleteTable(creds, doesNotExist);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.exportTable(creds, doesNotExist, "/tmp");
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.flushTable(creds, doesNotExist, null, null, false);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.getIteratorSetting(creds, doesNotExist, "foo", IteratorScope.SCAN);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.getLocalityGroups(creds, doesNotExist);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.getMaxRow(creds, doesNotExist, Collections.<ByteBuffer>emptySet(), null, false, null, false);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.getTableProperties(creds, doesNotExist);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.grantTablePermission(creds, "root", doesNotExist, TablePermission.WRITE);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.hasTablePermission(creds, "root", doesNotExist, TablePermission.WRITE);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        MiniAccumuloClusterImpl cluster = SharedMiniClusterBase.getCluster();
        Path base = cluster.getTemporaryPath();
        Path importDir = new Path(base, "importDir");
        Path failuresDir = new Path(base, "failuresDir");
        assertTrue(cluster.getFileSystem().mkdirs(importDir));
        assertTrue(cluster.getFileSystem().mkdirs(failuresDir));
        client.importDirectory(creds, doesNotExist, importDir.toString(), failuresDir.toString(), true);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.listConstraints(creds, doesNotExist);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.listSplits(creds, doesNotExist, 10000);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.mergeTablets(creds, doesNotExist, null, null);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.offlineTable(creds, doesNotExist, false);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.onlineTable(creds, doesNotExist, false);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.removeConstraint(creds, doesNotExist, 0);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.removeIterator(creds, doesNotExist, "name", EnumSet.allOf(IteratorScope.class));
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.removeTableProperty(creds, doesNotExist, Property.TABLE_FILE_MAX.getKey());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.renameTable(creds, doesNotExist, "someTableName");
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.revokeTablePermission(creds, "root", doesNotExist, TablePermission.ALTER_TABLE);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.setTableProperty(creds, doesNotExist, Property.TABLE_FILE_MAX.getKey(), "0");
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.splitRangeByTablets(creds, doesNotExist,
                client.getRowRange(ByteBuffer.wrap("row".getBytes(UTF_8))), 10);
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.updateAndFlush(creds, doesNotExist, new HashMap<ByteBuffer, List<ColumnUpdate>>());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.getDiskUsage(creds, Collections.singleton(doesNotExist));
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.testTableClassLoad(creds, doesNotExist, VersioningIterator.class.getName(),
                SortedKeyValueIterator.class.getName());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
    try {
        client.createConditionalWriter(creds, doesNotExist, new ConditionalWriterOptions());
        fail("exception not thrown");
    } catch (TableNotFoundException ex) {
    }
}

From source file:com.foglyn.fogbugz.FogBugzClient.java

public void loadCaches(IProgressMonitor monitor) throws FogBugzException {
    loadCaches(EnumSet.allOf(CacheType.class), monitor);
}