Package org.gatein.management.api.exceptions

Examples of org.gatein.management.api.exceptions.OperationException


            } else if (site.getObjectType() == ObjectType.GROUP_SITE) {
                children.add("group");
            } else if (site.getObjectType() == ObjectType.USER_SITE) {
                children.add("user");
            } else {
                throw new OperationException(operationContext.getOperationName(), "Unknown site type " + site.getObjectType());
            }
        } else {
            if (site.getObjectType() == ObjectType.GROUP_SITE) {
                Collection<? extends Site> groupsites = site.getWorkspace().getSites(site.getObjectType());
                for (Site groupsite : groupsites) {
View Full Code Here


        try {
            PortalConfig portalConfig = dataStorage.getPortalConfig(siteKey.getTypeName(), siteKey.getName());
            resultHandler.completed(portalConfig);
        } catch (Exception e) {
            throw new OperationException(operationContext.getOperationName(),
                    "Could not retrieve site layout for site " + site, e);
        }
    }
View Full Code Here

        // retrieve pages
        if (pageName == null) {
            try {
                resultHandler.completed(PageUtils.getAllPages(dataStorage, pageService, siteKey));
            } catch (Exception e) {
                throw new OperationException(operationName, "Could not retrieve pages for site " + siteKey);
            }
        } else {
            PageKey key = new PageKey(siteKey, pageName);
            try {
                Page page = PageUtils.getPage(dataStorage, pageService, key);
                if (page == null) {
                    throw new ResourceNotFoundException("No page found for " + key);
                } else {
                    resultHandler.completed(page);
                }
            } catch (ResourceNotFoundException e) {
                throw e;
            } catch (OperationException e) {
                throw e;
            } catch (Exception e) {
                throw new OperationException(operationName, "Operation failed getting page for " + key, e);
            }
        }
    }
View Full Code Here

            OperationException {
        final String operationName = operationContext.getOperationName();

        OperationAttachment attachment = operationContext.getAttachment(true);
        if (attachment == null)
            throw new OperationException(operationContext.getOperationName(), "No attachment available for MOP import.");

        InputStream inputStream = attachment.getStream();
        if (inputStream == null)
            throw new OperationException(operationContext.getOperationName(), "No data stream available for import.");

        final POMSessionManager mgr = operationContext.getRuntimeContext().getRuntimeComponent(POMSessionManager.class);
        POMSession session = mgr.getSession();
        if (session == null)
            throw new OperationException(operationName, "MOP session was null");

        Workspace workspace = session.getWorkspace();
        if (workspace == null)
            throw new OperationException(operationName, "MOP workspace was null");

        DataStorage dataStorage = operationContext.getRuntimeContext().getRuntimeComponent(DataStorage.class);
        if (dataStorage == null)
            throw new OperationException(operationName, "DataStorage was null");

        PageService pageService = operationContext.getRuntimeContext().getRuntimeComponent(PageService.class);
        if (pageService == null)
            throw new OperationException(operationName, "PageService was null");

        NavigationService navigationService = operationContext.getRuntimeContext().getRuntimeComponent(NavigationService.class);
        if (navigationService == null)
            throw new OperationException(operationName, "Navigation service was null");

        DescriptionService descriptionService = operationContext.getRuntimeContext().getRuntimeComponent(
                DescriptionService.class);
        if (descriptionService == null)
            throw new OperationException(operationName, "Description service was null");

        String mode = operationContext.getAttributes().getValue("importMode");
        if (mode == null || "".equals(mode))
            mode = "merge";

        ImportMode importMode;
        try {
            importMode = ImportMode.valueOf(mode.trim().toUpperCase());
        } catch (Exception e) {
            throw new OperationException(operationName, "Unknown importMode " + mode);
        }

        Map<SiteKey, MopImport> importMap = new HashMap<SiteKey, MopImport>();
        final NonCloseableZipInputStream zis = new NonCloseableZipInputStream(inputStream);
        ZipEntry entry;
        boolean empty = false;
        try {
            log.info("Preparing data for import.");
            while ((entry = zis.getNextEntry()) != null) {
                // Skip directories
                if (entry.isDirectory())
                    continue;
                // Skip empty entries (this allows empty zip files to not cause exceptions).
                empty = entry.getName().equals("");
                if (empty)
                    continue;

                // Parse zip entry
                String[] parts = parseEntry(entry);
                SiteKey siteKey = Utils.siteKey(parts[0], parts[1]);
                String file = parts[2];

                MopImport mopImport = importMap.get(siteKey);
                if (mopImport == null) {
                    mopImport = new MopImport();
                    importMap.put(siteKey, mopImport);
                }

                if (SiteLayoutExportTask.FILES.contains(file)) {
                    // Unmarshal site layout data
                    Marshaller<PortalConfig> marshaller = operationContext.getBindingProvider().getMarshaller(
                            PortalConfig.class, ContentType.XML);
                    PortalConfig portalConfig = marshaller.unmarshal(zis);
                    portalConfig.setType(siteKey.getTypeName());
                    if (!portalConfig.getName().equals(siteKey.getName())) {
                        throw new OperationException(operationName,
                                "Name of site does not match that of the zip entry site name.");
                    }

                    // Add import task to run later
                    mopImport.siteTask = new SiteLayoutImportTask(portalConfig, siteKey, dataStorage);
                } else if (file.equals(PageExportTask.FILE)) {
                    // Unmarshal page data
                    Marshaller<Page.PageSet> marshaller = operationContext.getBindingProvider().getMarshaller(
                            Page.PageSet.class, ContentType.XML);
                    Page.PageSet pages = marshaller.unmarshal(zis);
                    for (Page page : pages.getPages()) {
                        page.setOwnerType(siteKey.getTypeName());
                        page.setOwnerId(siteKey.getName());
                    }

                    // Obtain the site from the session when it's needed.
                    MOPSiteProvider siteProvider = new MOPSiteProvider() {
                        @Override
                        public Site getSite(SiteKey siteKey) {
                            return mgr.getSession().getWorkspace()
                                    .getSite(Utils.getObjectType(siteKey.getType()), siteKey.getName());
                        }
                    };
                    // Add import task to run later.
                    mopImport.pageTask = new PageImportTask(pages, siteKey, dataStorage, pageService, siteProvider);
                } else if (file.equals(NavigationExportTask.FILE)) {
                    // Unmarshal navigation data
                    Marshaller<PageNavigation> marshaller = operationContext.getBindingProvider().getMarshaller(
                            PageNavigation.class, ContentType.XML);
                    PageNavigation navigation = marshaller.unmarshal(zis);
                    navigation.setOwnerType(siteKey.getTypeName());
                    navigation.setOwnerId(siteKey.getName());

                    // Add import task to run later
                    mopImport.navigationTask = new NavigationImportTask(navigation, siteKey, navigationService,
                            descriptionService, dataStorage);
                }
            }

            resultHandler.completed(NoResultModel.INSTANCE);
        } catch (Throwable t) {
            throw new OperationException(operationContext.getOperationName(), "Exception reading data for import.", t);
        } finally {
            try {
                zis.reallyClose();
            } catch (IOException e) {
                log.warn("Exception closing underlying data stream from import.");
            }
        }

        if (empty) {
            log.info("Nothing to import, zip file empty.");
            return;
        }

        // Perform import
        Map<SiteKey, MopImport> importsRan = new HashMap<SiteKey, MopImport>();
        try {
            log.info("Performing import using importMode '" + mode + "'");
            for (Map.Entry<SiteKey, MopImport> mopImportEntry : importMap.entrySet()) {
                SiteKey siteKey = mopImportEntry.getKey();
                MopImport mopImport = mopImportEntry.getValue();
                MopImport ran = new MopImport();

                if (importsRan.containsKey(siteKey)) {
                    throw new IllegalStateException("Multiple site imports for same operation.");
                }
                importsRan.put(siteKey, ran);

                log.debug("Importing data for site " + siteKey);

                // Site layout import
                if (mopImport.siteTask != null) {
                    log.debug("Importing site layout data.");
                    ran.siteTask = mopImport.siteTask;
                    mopImport.siteTask.importData(importMode);
                }

                // Page import
                if (mopImport.pageTask != null) {
                    log.debug("Importing page data.");
                    ran.pageTask = mopImport.pageTask;
                    mopImport.pageTask.importData(importMode);
                }

                // Navigation import
                if (mopImport.navigationTask != null) {
                    log.debug("Importing navigation data.");
                    ran.navigationTask = mopImport.navigationTask;
                    mopImport.navigationTask.importData(importMode);
                }
            }
            log.info("Import successful !");
        } catch (Throwable t) {
            boolean rollbackSuccess = true;
            log.error("Exception importing data.", t);
            log.info("Attempting to rollback data modified by import.");
            for (Map.Entry<SiteKey, MopImport> mopImportEntry : importsRan.entrySet()) {
                SiteKey siteKey = mopImportEntry.getKey();
                MopImport mopImport = mopImportEntry.getValue();

                log.debug("Rolling back imported data for site " + siteKey);
                if (mopImport.navigationTask != null) {
                    log.debug("Rolling back navigation modified during import...");
                    try {
                        mopImport.navigationTask.rollback();
                    } catch (Throwable t1) // Continue rolling back even though there are exceptions.
                    {
                        rollbackSuccess = false;
                        log.error("Error rolling back navigation data for site " + siteKey, t1);
                    }
                }
                if (mopImport.pageTask != null) {
                    log.debug("Rolling back pages modified during import...");
                    try {
                        mopImport.pageTask.rollback();
                    } catch (Throwable t1) // Continue rolling back even though there are exceptions.
                    {
                        rollbackSuccess = false;
                        log.error("Error rolling back page data for site " + siteKey, t1);
                    }
                }
                if (mopImport.siteTask != null) {
                    log.debug("Rolling back site layout modified during import...");
                    try {
                        mopImport.siteTask.rollback();
                    } catch (Throwable t1) // Continue rolling back even though there are exceptions.
                    {
                        rollbackSuccess = false;
                        log.error("Error rolling back site layout for site " + siteKey, t1);
                    }
                }
            }

            String message = (rollbackSuccess) ? "Error during import. Tasks successfully rolled back. Portal should be back to consistent state."
                    : "Error during import. Errors in rollback as well. Portal may be in an inconsistent state.";

            throw new OperationException(operationName, message, t);
        } finally {
            importMap.clear();
            importsRan.clear();
        }
    }
View Full Code Here

        String operationName = operationContext.getOperationName();
        PathAddress address = operationContext.getAddress();

        String siteType = address.resolvePathTemplate("site-type");
        if (siteType == null)
            throw new OperationException(operationName, "Site type was not specified.");

        ObjectType<Site> objectType = Utils.getObjectType(Utils.getSiteType(siteType));
        if (objectType == null) {
            throw new ResourceNotFoundException("No site type found for " + siteType);
        }

        POMSessionManager mgr = operationContext.getRuntimeContext().getRuntimeComponent(POMSessionManager.class);
        POMSession session = mgr.getSession();
        if (session == null)
            throw new OperationException(operationName, "MOP session was null");

        Workspace workspace = session.getWorkspace();
        if (workspace == null)
            throw new OperationException(operationName, "MOP workspace was null");

        execute(operationContext, resultHandler, workspace, objectType);
    }
View Full Code Here

        StepResultHandler<PageNavigation> stepResultHandler = new StepResultHandler<PageNavigation>(address) {
            @Override
            public void failed(String failureDescription) {
                if (address.equals(getCurrentAddress())) {
                    throw new OperationException(operationName, "Navigation export failed. Reason: " + failureDescription);
                } else {
                    throw new OperationException(operationName, "Navigation export failed. Reason: " + failureDescription
                            + " [Step Address: " + getCurrentAddress() + "]");
                }
            }

            @Override
            protected void doCompleted(PageNavigation result) {
                if (getResults().isEmpty()) {
                    super.doCompleted(result);
                } else {
                    PageNavigation navigation = getResults().get(0);
                    merge(navigation, result);
                }
            }
        };

        try {
            executeHandlers(resource, operationContext, address, OperationNames.READ_CONFIG_AS_XML, stepResultHandler, filter,
                    true);
            List<PageNavigation> results = stepResultHandler.getResults();
            if (results.isEmpty()) {
                resultHandler.completed(new ExportResourceModel(Collections.<ExportTask> emptyList()));
            } else {
                NavigationExportTask task = new NavigationExportTask(stepResultHandler.getResults().get(0), marshaller);
                resultHandler.completed(new ExportResourceModel(task));
            }
        } catch (ResourceNotFoundException e) {
            throw e;
        } catch (OperationException e) {
            throw new OperationException(e.getOperationName(), getStepMessage(e, address, stepResultHandler), e);
        } catch (Throwable t) {
            throw new OperationException(operationName, getStepMessage(t, address, stepResultHandler), t);
        }
    }
View Full Code Here

                public String getOperationName() {
                    return OperationNames.READ_RESOURCE;
                }
            }, readResourceResult);
            if (readResourceResult.getFailureDescription() != null) {
                throw new OperationException(operationName, "Failure '" + readResourceResult.getFailureDescription()
                        + "' encountered executing " + OperationNames.READ_RESOURCE);
            }

            Object model = readResourceResult.getResult();
            if (!(model instanceof ReadResourceModel)) {
View Full Code Here

      Class<T> type = getParameterizedType();
      Marshaller<T> marshaller = operationContext.getBindingProvider().getMarshaller(type, operationContext.getContentType());

      if (marshaller == null)
      {
         throw new OperationException(operationContext.getOperationName(),
            "No marshaller found for type " + type + " and content type " + operationContext.getContentType() +
               " at address " + operationContext.getAddress());
      }

      try
      {
         execute(operationContext, marshaller.unmarshal(attachment.getStream()));
      }
      catch (BindingException e)
      {
         throw new OperationException(operationContext.getOperationName(),
            "Exception unmarshalling data for type " + type + " and content type " + operationContext.getContentType() +
               " at address " + operationContext.getAddress(), e);
      }
   }
View Full Code Here

        List<String> filterAttributes = operationContext.getAttributes().getValues("filter");
        PathTemplateFilter filter;
        try {
            filter = PathTemplateFilter.parse(filterAttributes);
        } catch (ParseException e) {
            throw new OperationException(operationContext.getOperationName(), "Could not parse filter attributes.", e);
        }

        if (filter.hasPathTemplate("nav-uri")) {
            filtered.execute(operationContext, resultHandler, filter);
        } else {
View Full Code Here

            OperationException {
        final String operationName = operationContext.getOperationName();

        OperationAttachment attachment = operationContext.getAttachment(true);
        if (attachment == null)
            throw new OperationException(operationContext.getOperationName(), "No attachment available for MOP import.");

        InputStream inputStream = attachment.getStream();
        if (inputStream == null)
            throw new OperationException(operationContext.getOperationName(), "No data stream available for import.");

        final POMSessionManager mgr = operationContext.getRuntimeContext().getRuntimeComponent(POMSessionManager.class);
        POMSession session = mgr.getSession();
        if (session == null)
            throw new OperationException(operationName, "MOP session was null");

        Workspace workspace = session.getWorkspace();
        if (workspace == null)
            throw new OperationException(operationName, "MOP workspace was null");

        DataStorage dataStorage = operationContext.getRuntimeContext().getRuntimeComponent(DataStorage.class);
        if (dataStorage == null)
            throw new OperationException(operationName, "DataStorage was null");

        PageService pageService = operationContext.getRuntimeContext().getRuntimeComponent(PageService.class);
        if (pageService == null)
            throw new OperationException(operationName, "PageService was null");

        NavigationService navigationService = operationContext.getRuntimeContext().getRuntimeComponent(NavigationService.class);
        if (navigationService == null)
            throw new OperationException(operationName, "Navigation service was null");

        DescriptionService descriptionService = operationContext.getRuntimeContext().getRuntimeComponent(
                DescriptionService.class);
        if (descriptionService == null)
            throw new OperationException(operationName, "Description service was null");

        ChromatticManager chromatticManager = operationContext.getRuntimeContext().getRuntimeComponent(ChromatticManager.class);
        if (chromatticManager == null) throw new OperationException(operationName, "Chromattic manager was null");

        String mode = operationContext.getAttributes().getValue("importMode");
        if (mode == null || "".equals(mode))
            mode = "merge";

        ImportMode importMode;
        try {
            importMode = ImportMode.valueOf(mode.trim().toUpperCase());
        } catch (Exception e) {
            throw new OperationException(operationName, "Unknown importMode " + mode);
        }

        Map<SiteKey, MopImport> importMap = new HashMap<SiteKey, MopImport>();
        final NonCloseableZipInputStream zis = new NonCloseableZipInputStream(inputStream);
        ZipEntry entry;
        boolean empty = false;
        try {
            log.info("Preparing data for import.");
            while ((entry = zis.getNextEntry()) != null) {
                // Skip directories
                if (entry.isDirectory())
                    continue;
                // Skip empty entries (this allows empty zip files to not cause exceptions).
                empty = entry.getName().equals("");
                if (empty)
                    continue;

                // Parse zip entry
                String[] parts = parseEntry(entry);
                SiteKey siteKey = Utils.siteKey(parts[0], parts[1]);
                String file = parts[2];

                MopImport mopImport = importMap.get(siteKey);
                if (mopImport == null) {
                    mopImport = new MopImport();
                    importMap.put(siteKey, mopImport);
                }

                if (SiteLayoutExportTask.FILES.contains(file)) {
                    // Unmarshal site layout data
                    Marshaller<PortalConfig> marshaller = operationContext.getBindingProvider().getMarshaller(
                            PortalConfig.class, ContentType.XML);
                    PortalConfig portalConfig = marshaller.unmarshal(zis);
                    portalConfig.setType(siteKey.getTypeName());
                    if (!portalConfig.getName().equals(siteKey.getName())) {
                        throw new OperationException(operationName,
                                "Name of site does not match that of the zip entry site name.");
                    }

                    // Add import task to run later
                    mopImport.siteTask = new SiteLayoutImportTask(portalConfig, siteKey, dataStorage);
                } else if (file.equals(PageExportTask.FILE)) {
                    // Unmarshal page data
                    Marshaller<Page.PageSet> marshaller = operationContext.getBindingProvider().getMarshaller(
                            Page.PageSet.class, ContentType.XML);
                    Page.PageSet pages = marshaller.unmarshal(zis);
                    for (Page page : pages.getPages()) {
                        page.setOwnerType(siteKey.getTypeName());
                        page.setOwnerId(siteKey.getName());
                    }

                    // Obtain the site from the session when it's needed.
                    MOPSiteProvider siteProvider = new MOPSiteProvider() {
                        @Override
                        public Site getSite(SiteKey siteKey) {
                            return mgr.getSession().getWorkspace()
                                    .getSite(Utils.getObjectType(siteKey.getType()), siteKey.getName());
                        }
                    };
                    // Add import task to run later.
                    mopImport.pageTask = new PageImportTask(pages, siteKey, dataStorage, pageService, siteProvider);
                } else if (file.equals(NavigationExportTask.FILE)) {
                    // Unmarshal navigation data
                    Marshaller<PageNavigation> marshaller = operationContext.getBindingProvider().getMarshaller(
                            PageNavigation.class, ContentType.XML);
                    PageNavigation navigation = marshaller.unmarshal(zis);
                    navigation.setOwnerType(siteKey.getTypeName());
                    navigation.setOwnerId(siteKey.getName());

                    // Add import task to run later
                    mopImport.navigationTask = new NavigationImportTask(navigation, siteKey, navigationService,
                            descriptionService, dataStorage);
                }
            }

            resultHandler.completed(NoResultModel.INSTANCE);
        } catch (Throwable t) {
            throw new OperationException(operationContext.getOperationName(), "Exception reading data for import.", t);
        } finally {
            try {
                zis.reallyClose();
            } catch (IOException e) {
                log.warn("Exception closing underlying data stream from import.");
            }
        }

        if (empty) {
            log.info("Nothing to import, zip file empty.");
            return;
        }

        // Perform import
        Map<SiteKey, MopImport> importsRan = new HashMap<SiteKey, MopImport>();
        OperationException importError = null;
        try {
            log.info("Performing import using importMode '" + mode + "'");
            for (Map.Entry<SiteKey, MopImport> mopImportEntry : importMap.entrySet()) {
                SiteKey siteKey = mopImportEntry.getKey();
                MopImport mopImport = mopImportEntry.getValue();
                MopImport ran = new MopImport();

                if (importsRan.containsKey(siteKey)) {
                    throw new IllegalStateException("Multiple site imports for same operation.");
                }
                importsRan.put(siteKey, ran);

                log.debug("Importing data for site " + siteKey);

                // Site layout import
                if (mopImport.siteTask != null) {
                    log.debug("Importing site layout data.");
                    ran.siteTask = mopImport.siteTask;
                    mopImport.siteTask.importData(importMode);
                }

                // Page import
                if (mopImport.pageTask != null) {
                    log.debug("Importing page data.");
                    ran.pageTask = mopImport.pageTask;
                    mopImport.pageTask.importData(importMode);
                }

                // Navigation import
                if (mopImport.navigationTask != null) {
                    log.debug("Importing navigation data.");
                    ran.navigationTask = mopImport.navigationTask;
                    mopImport.navigationTask.importData(importMode);
                }
            }
            log.info("Import successful !");
        } catch (Throwable t) {
            boolean rollbackSuccess = true;
            log.error("Exception importing data.", t);
            log.info("Attempting to rollback data modified by import.");
            for (Map.Entry<SiteKey, MopImport> mopImportEntry : importsRan.entrySet()) {
                SiteKey siteKey = mopImportEntry.getKey();
                MopImport mopImport = mopImportEntry.getValue();

                log.debug("Rolling back imported data for site " + siteKey);
                if (mopImport.navigationTask != null) {
                    log.debug("Rolling back navigation modified during import...");
                    try {
                        mopImport.navigationTask.rollback();
                    } catch (Throwable t1) // Continue rolling back even though there are exceptions.
                    {
                        rollbackSuccess = false;
                        log.error("Error rolling back navigation data for site " + siteKey, t1);
                    }
                }
                if (mopImport.pageTask != null) {
                    log.debug("Rolling back pages modified during import...");
                    try {
                        mopImport.pageTask.rollback();
                    } catch (Throwable t1) // Continue rolling back even though there are exceptions.
                    {
                        rollbackSuccess = false;
                        log.error("Error rolling back page data for site " + siteKey, t1);
                    }
                }
                if (mopImport.siteTask != null) {
                    log.debug("Rolling back site layout modified during import...");
                    try {
                        mopImport.siteTask.rollback();
                    } catch (Throwable t1) // Continue rolling back even though there are exceptions.
                    {
                        rollbackSuccess = false;
                        log.error("Error rolling back site layout for site " + siteKey, t1);
                    }
                }
            }

            String message = (rollbackSuccess) ? "Error during import. Tasks successfully rolled back. Portal should be back to consistent state."
                    : "Error during import. Errors in rollback as well. Portal may be in an inconsistent state.";

            importError = new OperationException(operationName, message, t);
        } finally {
            importMap.clear();
            importsRan.clear();
        }
View Full Code Here

TOP

Related Classes of org.gatein.management.api.exceptions.OperationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.