Package org.gatein.management.api.exceptions

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


         return pages;
      }
      catch (Exception e)
      {
         throw new OperationException(operationName, "Could not retrieve pages for site " + siteKey);
      }
   }
View Full Code Here


                     params[i] = DmrModelValue.readFromJsonStream(attachment.getStream());
                  }
                  catch (IOException e)
                  {
                     log.error("IOException reading from JSON stream for detyped model.", e);
                     throw new OperationException(operationName, "Could not properly read data stream. See log for more details.", e);
                  }
               }
               else
               {
                  throw new OperationException(operationName, "Data stream not available.");
               }
            }
            else if (ModelProvider.class.isAssignableFrom(parameterType))
            {
               @SuppressWarnings("unchecked")
               Class<? extends ModelValue> type = (Class<? extends ModelValue>) parameterType;
               params[i] = operationContext.newModel(type);
            }
            else if (OperationContext.class == parameterType)
            {
               params[i] = operationContext;
            }
         }
         else
         {
            Class<?> marshalClass = method.getParameterTypes()[i];
            if (debug) log.debug("Encountered unannotated parameter. Will try and find marshaller for type " + marshalClass);

            // Currently only one attachment is supported, and that's the data stream (input) of the management operation.
            if (attachment != null)
            {
               throw new RuntimeException("Cannot unmarshal " + marshalClass + " for method " + methodName +
                  " and component " + managedClass.getName() + ". This is because input stream was already consumed. " +
                  "This can happen if the marshaled type is not declared before @ManagedContext for detyped ModelValue type.");
            }
            Marshaller<?> marshaller = operationContext.getBindingProvider().getMarshaller(marshalClass, operationContext.getContentType());
            if (marshaller != null)
            {
               attachment = operationContext.getAttachment(true);
               if (attachment == null) throw new OperationException(operationName, "No attachment was found for this operation.");

               params[i] = marshaller.unmarshal(attachment.getStream());
               if (debug) log.debug("Successfully unmarshaled object of type " + marshalClass);
            }
            else
View Full Code Here

         }
      }
      else
      {
         // Why pass in operation name, if it's not used as part of the message...
         throw new OperationException(operationName, "Operation '" + operationName  + "' not found for address '" + address + "'");
      }
   }
View Full Code Here

         @Override
         public void failed(String failureDescription)
         {
            if (address.equals(getCurrentAddress()))
            {
               throw new OperationException(operationName, "Export operation failed. Reason: " + failureDescription);
            }
            else
            {
               throw new OperationException(operationName, "Export operation failed. Reason: " + failureDescription + " [Step Address: " + getCurrentAddress() + "]");
            }
         }
      };

      try
      {
         executeHandlers(resource, operationContext, address, operationName, exportResultHandler);
      }
      catch (OperationException e)
      {
         throw new OperationException(e.getOperationName(), getStepMessage(e, address, exportResultHandler), e);
      }
      catch (Throwable t)
      {
         throw new OperationException(operationName, getStepMessage(t, address, exportResultHandler), t);
      }

      List<ExportTask> tasks = new ArrayList<ExportTask>();
      for (ExportResourceModel model : exportResultHandler.getResults())
      {
View Full Code Here

         {
            filter = PathTemplateFilter.parse(filterAttributes);
         }
         catch (ParseException e)
         {
            throw new OperationException(operationName, "Could not parse filter attributes.", e);
         }

         if (address.accepts(filter))
         {
            handler.execute(operationContext, stepResultHandler);
         }
      }
      else
      {
         ManagedResource found = resource.getSubResource(address);
         if (found == null)
         {
            throw new OperationException(operationName, "Could not locate resource at address " + address);
         }
        
         OperationHandler readResource = resource.getOperationHandler(address, OperationNames.READ_RESOURCE);
         BasicResultHandler readResourceResult = new BasicResultHandler();
         readResource.execute(operationContext, 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

            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

            importMap = expandUserTemplate(attr, svc, templates);
        }

        validationRules(attr, importMap);

        OperationException importError = performImport(attr, importMap);

        endRequest(attr, svc, importError);

        resultHandler.completed(NoResultModel.INSTANCE);
    }
View Full Code Here

            attr.mode = "merge";

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

        // Expression for users. This option is valid when importType == user
        attr.targetExpr = operationContext.getAttributes().getValue("targetExpr");
View Full Code Here

            throws OperationException {

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

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

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

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

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

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

        svc.organizationService = operationContext.getRuntimeContext().getRuntimeComponent(OrganizationService.class);
        if (svc.organizationService == null)
            throw new OperationException(attr.operationName, "Organization service was null");

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

    }
View Full Code Here

        ArrayList<MopTemplate> templates = new ArrayList<MopTemplate>();
        // Gets .zip attachment
        OperationAttachment attachment = operationContext.getAttachment(true);
        if (attachment == null)
            throw new OperationException(attr.operationName,
                                         "No attachment available for " + attr.importType + " template import.");

        InputStream inputStream = attachment.getStream();
        if (inputStream == null)
            throw new OperationException(attr.operationName,
                                         "No data stream available for " + attr.importType + " template import.");

        // Reads .zip file
        final NonCloseableZipInputStream zis = new NonCloseableZipInputStream(inputStream);
        ZipEntry entry;

        boolean portal = false, group = false, user = false, template = false;
        try {
            log.info("Preparing data for import.");
            while ((entry = zis.getNextEntry()) != null) {
                // Skip directories
                if (entry.isDirectory()) {
                    // Directory entries finish with "/"
                    String[] folders = entry.getName().split("/");
                    String name = folders[folders.length - 1];
                    // 1st directory entry
                    if (!(portal || group || user)) {
                        if (DIR.contains(name)) {
                            if ("portal".equals(name)) {
                                portal = true;
                                if (!"portal".equalsIgnoreCase(attr.importType))
                                    throw new ZipTemplateException(".zip contains a portal folder but not " +
                                                                   "/template/portal operation found, " +
                                                                   "instead /template/" + attr.importType + " .");
                            } else if ("group".equals(name)) {
                                group = true;
                                if (!"group".equalsIgnoreCase(attr.importType))
                                    throw new ZipTemplateException(".zip contains a group folder but not " +
                                                                   "/template/group operation found, " +
                                                                   "instead /template/" + attr.importType + " .");
                            } else if ("user".equals(name)) {
                                user = true;
                                if (!"user".equalsIgnoreCase(attr.importType))
                                    throw new ZipTemplateException(".zip contains a user folder but not " +
                                                                   "/template/user operation found, " +
                                                                   "instead /template/" + attr.importType + " .");
                            }
                        } else {
                            throw new ZipTemplateException(".zip contains a not valid folder: " + name + ". " +
                                                           "Expecting one of " + DIR);
                        }
                    } else {
                        // 2nd directory entry
                        if (!template) {
                            if ("template".equals(name)) {
                                template = true;
                                if (group) {
                                    MopTemplate groupTemplate = new MopTemplate();
                                    groupTemplate.templateType = SiteType.GROUP;
                                    templates.add(groupTemplate);
                                } else if (user) {
                                    MopTemplate userTemplate = new MopTemplate();
                                    userTemplate.templateType = SiteType.USER;
                                    templates.add(userTemplate);
                                }
                            } else
                                throw new ZipTemplateException(".zip does not contains a template folder under " +
                                                               "portal/group/user folder, instead " + name + " .");
                        } else {
                            // 3rd directory
                            if (portal) {
                                MopTemplate portalTemplate = new MopTemplate();
                                portalTemplate.templateName = name;
                                portalTemplate.templateType = SiteType.PORTAL;
                                templates.add(portalTemplate);
                            } else {
                                throw new ZipTemplateException(".zip contains a folder under {portal,group,user}/template/ " +
                                                               "layout. It is expected one of " + FILES);
                            }
                        }
                    }
                    continue;
                }

                // Parses zip entry
                String[] parts = parseEntry(entry, portal);
                // Expected filesystem as
                //      portal/template/<templateName>/{portal,pages,navigation}.xml
                //      group/template/{group,pages,navigation}.xml
                //      user/template/{user,pages.navigation}.xml
                String file;
                if (portal)
                    file = parts[3];
                else
                    file = parts[2];

                // Validates file name
                if (!FILES.contains(file)) {
                    log.warn(".zip contains a not valid template file: " + file + ". Skipping...");
                    continue;
                }

                // Validates that a portal.xml is used with /template/portal operation
                if ("portal.xml".equals(file) && !portal) {
                    log.warn("portal.xml in .zip but not /template/portal operation found, " +
                            "instead /template/" + attr.importType + " . Skipping... ");
                    continue;
                }

                // Validates that a group.xml is used with /template/group operation
                if ("group.xml".equals(file) && !group) {
                    log.warn("group.xml in .zip but not /template/group operation found, " +
                            "instead /template/" + attr.importType + " . Skipping...");
                    continue;
                }

                // Validates that a user.xml is used with /template/user operation
                if ("user.xml".equals(file) && !user) {
                    log.warn("user.xml in .zip but not /template/user operation found, " +
                            "instead /template/" + attr.importType + " . Skipping... ");
                    continue;
                }

                // Templates are unmarshalled in generic objects, pattern substitution will be performed later
                if (SiteLayoutExportTask.FILES.contains(file)) {
                    Marshaller<PortalConfig> marshaller = operationContext.getBindingProvider()
                            .getMarshaller(PortalConfig.class, ContentType.XML);
                    templates.get(templates.size() - 1).portalConfig = marshaller.unmarshal(zis);
                } else if (file.equals(PageExportTask.FILE)) {
                    Marshaller<Page.PageSet> marshaller = operationContext.getBindingProvider()
                            .getMarshaller(Page.PageSet.class, ContentType.XML);
                    templates.get(templates.size() - 1).pageSet = marshaller.unmarshal(zis);
                } else if (file.equals(NavigationExportTask.FILE)) {
                    Marshaller<PageNavigation> marshaller = operationContext.getBindingProvider()
                            .getMarshaller(PageNavigation.class, ContentType.XML);
                    templates.get(templates.size() - 1).pageNavigation = marshaller.unmarshal(zis);
                }
            }

        } 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.");
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.