Package org.infoglue.cms.webservices.elements

Examples of org.infoglue.cms.webservices.elements.StatusBean


    public StatusBean setAccessRights(final String principalName, final Object[] inputsArray)
    {
        if(!ServerNodeController.getController().getIsIPAllowed(getRequest()))
        {
            logger.error("A client with IP " + getRequest().getRemoteAddr() + " was denied access to the webservice. Could be a hack attempt or you have just not configured the allowed IP-addresses correct.");
            return new StatusBean(false, "You are not allowed to talk to this service");
        }

      StatusBean statusBean = new StatusBean(true, "ok");
     
        logger.info("****************************************");
        logger.info("Creating contents through webservice....");
        logger.info("****************************************");
       
        logger.info("principalName:" + principalName);
        logger.info("inputsArray:" + inputsArray);
        //logger.warn("contents:" + contents);
       
        try
        {
      final DynamicWebserviceSerializer serializer = new DynamicWebserviceSerializer();
            List accessRights = (List) serializer.deserialize(inputsArray);
          logger.info("accessRights:" + accessRights);

            initializePrincipal(principalName);

            if(accessRights != null)
            {
              Iterator accessRightsIterator = accessRights.iterator();
              while(accessRightsIterator.hasNext())
              {
                  Map accessRightMap = (Map)accessRightsIterator.next();
                 
                  String interceptionPointName     = (String)accessRightMap.get("interceptionPointName");
                  String interceptionPointCategory   = interceptionPointName.substring(0, interceptionPointName.indexOf("."));
                  String parameters           = (String)accessRightMap.get("parameters");
                  String clearOldAccessRights     = (String)accessRightMap.get("clearOldAccessRights");
                 
              AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer();
             
              if(interceptionPointCategory.equalsIgnoreCase("Content"))
              { 
                Integer contentId = new Integer(parameters);
                ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId);
                if(!contentVO.getCreatorName().equalsIgnoreCase(principal.getName()))
                {
                  Integer protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentId);
                  if(ContentControllerProxy.getController().getIsContentProtected(contentId) && !AccessRightController.getController().getIsPrincipalAuthorized(principal, "Content.ChangeAccessRights", protectedContentId.toString()))
                    ceb.add(new AccessConstraintException("Content.contentId", "1006"));
                }
              }
              else if(interceptionPointCategory.equalsIgnoreCase("SiteNodeVersion"))
              { 
                Integer siteNodeVersionId = new Integer(parameters);
                SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId);
                if(!siteNodeVersionVO.getVersionModifier().equalsIgnoreCase(principal.getName()))
                {
                  Integer protectedSiteNodeVersionId = SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getProtectedSiteNodeVersionId(siteNodeVersionId);
                  if(protectedSiteNodeVersionId != null && !AccessRightController.getController().getIsPrincipalAuthorized(principal, "SiteNodeVersion.ChangeAccessRights", siteNodeVersionId.toString()))
                    ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeId", "1006"));
                }
              }
              else
              {
                ceb.add(new AccessConstraintException("Repository.repositoryId", "1006"));
              }
             
              ceb.throwIfNotEmpty();

                 
                  Database db = CastorDatabaseService.getDatabase();
            beginTransaction(db);
           
            try
            {
                    InterceptionPoint interceptionPoint = InterceptionPointController.getController().getInterceptionPointWithName(interceptionPointName, db);
                   
                    logger.info("interceptionPointName:" + interceptionPointName);
                  logger.info("parameters:" + parameters);
 
                  AccessRightVO accessRightVO = new AccessRightVO();
                  accessRightVO.setParameters("" + parameters);
                 
                  if(clearOldAccessRights != null && clearOldAccessRights.equalsIgnoreCase("true"))
                    AccessRightController.getController().delete(interceptionPoint.getId(), parameters, true, db);
                 
                  AccessRight accessRight = AccessRightController.getController().create(accessRightVO, interceptionPoint, db);
                 
                  List accessRightRoles = (List)accessRightMap.get("accessRightRoles");
                  if(accessRightRoles != null)
                  {
                    Iterator accessRightRolesIterator = accessRightRoles.iterator();
                    while(accessRightRolesIterator.hasNext())
                    {
                        String roleName = (String)accessRightRolesIterator.next();
                       
                  AccessRightRoleVO accessRightRoleVO = new AccessRightRoleVO();
                  accessRightRoleVO.setRoleName(roleName);
                  AccessRightRole accessRightRole = AccessRightController.getController().createAccessRightRole(db, accessRightRoleVO, accessRight);
                  accessRight.getRoles().add(accessRightRole);
                    }
                  }
                 
                  List accessRightGroups = (List)accessRightMap.get("accessRightGroups");
                  if(accessRightGroups != null)
                  {
                    Iterator accessRightGroupsIterator = accessRightGroups.iterator();
                    while(accessRightGroupsIterator.hasNext())
                    {
                        String groupName = (String)accessRightGroupsIterator.next();
                       
                  AccessRightGroupVO accessRightGroupVO = new AccessRightGroupVO();
                  accessRightGroupVO.setGroupName(groupName);
                  AccessRightGroup accessRightGroup = AccessRightController.getController().createAccessRightGroup(db, accessRightGroupVO, accessRight);
                  accessRight.getGroups().add(accessRightGroup);
                    }
                  }

                  List accessRightUsers = (List)accessRightMap.get("accessRightUsers");
                  if(accessRightUsers != null)
                  {
                    Iterator accessRightUsersIterator = accessRightUsers.iterator();
                    while(accessRightUsersIterator.hasNext())
                    {
                        String userName = (String)accessRightUsersIterator.next();
                       
                  AccessRightUserVO accessRightUserVO = new AccessRightUserVO();
                  accessRightUserVO.setUserName(userName);
                  AccessRightUser accessRightUser = AccessRightController.getController().createAccessRightUser(db, accessRightUserVO, accessRight);
                  accessRight.getUsers().add(accessRightUser);
                    }
                  }

            commitTransaction(db);
            }
            catch (Exception e)
            {
              logger.warn("An error occurred so we should not complete the transaction:" + e);
              rollbackTransaction(db);
              throw new SystemException(e.getMessage());
            }
          }
          }
        }
        catch(Throwable e)
        {
          statusBean.setStatus(false);
          statusBean.setMessage("En error occurred when we tried to create a new content:" + e.getMessage());
            logger.error("En error occurred when we tried to create a new content:" + e.getMessage(), e);
        }
       
        updateCaches();

View Full Code Here


    public StatusBean updateUser(final String principalName, final Object[] inputsArray, String[] roleNames, String[] groupNames)
    {
        if(!ServerNodeController.getController().getIsIPAllowed(getRequest()))
        {
            logger.error("A client with IP " + getRequest().getRemoteAddr() + " was denied access to the webservice. Could be a hack attempt or you have just not configured the allowed IP-addresses correct.");
            return new StatusBean(false, "You are not allowed to talk to this service");
        }

        StatusBean statusBean = new StatusBean(true, "ok");
     
        logger.info("***************************************");
        logger.info("Updating user through webservice.......");
        logger.info("***************************************");
       
        try
        {
      final DynamicWebserviceSerializer serializer = new DynamicWebserviceSerializer();
            List users = (List) serializer.deserialize(inputsArray);
          logger.info("users:" + users);

            initializePrincipal(principalName);
           
          Iterator usersIterator = users.iterator();
          while(usersIterator.hasNext())
          {
              Map userMap = (Map)usersIterator.next();
             
              Boolean isPasswordChangeOperation   = (Boolean)userMap.get("isPasswordChangeOperation");
              Boolean isPasswordResetOperation  = (Boolean)userMap.get("isPasswordResetOperation");
             
              String firstName           = (String)userMap.get("firstName");
              String lastName           = (String)userMap.get("lastName");
              String email             = (String)userMap.get("email");
              String userName           = (String)userMap.get("userName");
              String password           = (String)userMap.get("password");
              String oldPassword           = (String)userMap.get("oldPassword");

              if(isPasswordChangeOperation)
              {
                logger.info("isPasswordChangeOperation");
                logger.info("userName:" + userName);
                logger.info("oldPassword:" + oldPassword);
                logger.info("password:" + password);
                userControllerProxy.updateUserPassword(userName, oldPassword, password);
              }
              else if(isPasswordResetOperation)
              {
                logger.info("isPasswordResetOperation");
                userControllerProxy.updateUserPassword(userName);
              }
              else
              {
                logger.info("isUserUpdateOperation");
                SystemUserVO systemUserVO = new SystemUserVO();
                systemUserVO.setEmail(email);
                systemUserVO.setFirstName(firstName);
                systemUserVO.setLastName(lastName);
                systemUserVO.setPassword(password);
                systemUserVO.setUserName(userName);
               
                if(roleNames != null && roleNames.length == 0)
                  roleNames = null;
                if(groupNames != null && groupNames.length == 0)
                  groupNames = null;
               
                userControllerProxy.updateUser(systemUserVO, oldPassword, roleNames, groupNames);
              }
          }
        }
        catch(Throwable e)
        {
          statusBean.setStatus(false);
          statusBean.setMessage("En error occurred when we tried to update one or more users:" + e.getMessage());
            logger.error("En error occurred when we tried to update one or more users:" + e.getMessage(), e);
        }
       
        updateCaches();

View Full Code Here

    public StatusBean createSiteNodes(final String principalName, final Object[] inputsArray)
    {
        if(!ServerNodeController.getController().getIsIPAllowed(getRequest()))
        {
            logger.error("A client with IP " + getRequest().getRemoteAddr() + " was denied access to the webservice. Could be a hack attempt or you have just not configured the allowed IP-addresses correct.");
            return new StatusBean(false, "You are not allowed to talk to this service");
        }

      StatusBean statusBean = new StatusBean(true, "ok");

        List newSiteNodeIdList = new ArrayList();
       
        logger.info("****************************************");
        logger.info("Creating sitenodes through webservice....");
        logger.info("****************************************");
       
        logger.info("principalName:" + principalName);
        logger.info("inputsArray:" + inputsArray);
       
        try
        {
      final DynamicWebserviceSerializer serializer = new DynamicWebserviceSerializer();
            List siteNodes = (List) serializer.deserialize(inputsArray);
          logger.info("siteNodes:" + siteNodes);

            initializePrincipal(principalName);
          Iterator siteNodesIterator = siteNodes.iterator();
          while(siteNodesIterator.hasNext())
          {
              Map siteNode = (Map)siteNodesIterator.next();
             
              String name             = (String)siteNode.get("name");
              Integer siteNodeTypeDefinitionId   = (Integer)siteNode.get("siteNodeTypeDefinitionId");
              Integer repositoryId         = (Integer)siteNode.get("repositoryId");
              Integer parentSiteNodeId       = (Integer)siteNode.get("parentSiteNodeId");
              //String siteNodePath         = (String)siteNode.get("siteNodePath");
              Integer pageTemplateContentId     = (Integer)siteNode.get("pageTemplateContentId");
             
              logger.info("name:" + name);
              logger.info("siteNodeTypeDefinitionId:" + siteNodeTypeDefinitionId);
              logger.info("repositoryId:" + repositoryId);
              logger.info("parentSiteNodeId:" + parentSiteNodeId);
              //logger.info("contentPath:" + contentPath);
             
              /*
              if(contentPath != null && !contentPath.equals(""))
              {
                Database db = CastorDatabaseService.getDatabase();
            beginTransaction(db);
           
            try
            {
              if(parentContentId != null)
              {
                StringBuffer path = new StringBuffer();
               
                Content parentContent = ContentController.getContentController().getContentWithId(parentContentId, db);
                path.insert(0, parentContent.getName() + "/");
                while(parentContent.getParentContent() != null)
                {
                  parentContent = parentContent.getParentContent();
                  if(parentContent != null && parentContent.getParentContent() != null)
                    path.insert(0, parentContent.getName() + "/");
                }

                contentPath = path.toString() + contentPath;
              }
             
                  ContentVO parentContentVO = ContentController.getContentController().getContentVOWithPath(repositoryId, contentPath, true, this.principal, db);
                  parentContentId = parentContentVO.getId();
                 
              commitTransaction(db);
            }
            catch(Exception e)
            {
              logger.error("An error occurred so we should not complete the transaction:" + e, e);
              rollbackTransaction(db);
              throw new SystemException(e.getMessage());
            }
              }
              */
             
               SiteNodeVO siteNodeVO = new SiteNodeVO();
               siteNodeVO.setName(name);
               siteNodeVO.setSiteNodeTypeDefinitionId(siteNodeTypeDefinitionId);
               siteNodeVO.setRepositoryId(repositoryId);
               siteNodeVO.setParentSiteNodeId(parentSiteNodeId);
               siteNodeVO.setIsBranch(true);
             
              if(siteNodeVO.getCreatorName() == null)
                siteNodeVO.setCreatorName(this.principal.getName());
             
              Database db = CastorDatabaseService.getDatabase();
              ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();

              beginTransaction(db);

              try
              {
                SiteNode newSiteNode = siteNodeControllerProxy.acCreate(this.principal, siteNodeVO.getParentSiteNodeId(), siteNodeVO.getSiteNodeTypeDefinitionId(), siteNodeVO.getRepositoryId(), siteNodeVO, db);
                SiteNodeVO newSiteNodeVO = newSiteNode.getValueObject();
                if(newSiteNode != null)
                  statusBean.getCreatedBeans().add(new CreatedEntityBean(SiteNodeVO.class.getName(), new Long(newSiteNodeVO.getId())));
               
                Content newMetaInfoContent = SiteNodeController.getController().createSiteNodeMetaInfoContent(db, newSiteNodeVO, siteNodeVO.getRepositoryId(), this.principal, pageTemplateContentId, new ArrayList());
                if(newMetaInfoContent != null)
                  statusBean.getCreatedBeans().add(new CreatedEntityBean(ContentVO.class.getName(), new Long(newMetaInfoContent.getId())));
                 
                //Should we also change state on newly created content version?
                /*
                if(stateId != null && !stateId.equals(ContentVersionVO.WORKING_STATE))
                {
                  List events = new ArrayList();
                ContentStateController.changeState(newContentVersionId, stateId, "Remote update from deliver", false, this.principal, newContentVO.getId(), events);
               
                if(stateId.equals(ContentVersionVO.PUBLISHED_STATE))
                {
                    PublicationVO publicationVO = new PublicationVO();
                    publicationVO.setName("Direct publication by " + this.principal.getName());
                    publicationVO.setDescription("Direct publication from deliver");
                    publicationVO.setRepositoryId(repositoryId);
                    publicationVO = PublicationController.getController().createAndPublish(publicationVO, events, false, this.principal);
                }
                }
          */
               
                  commitTransaction(db);
              }
              catch(Exception e)
              {
                  logger.error("An error occurred so we should not completes the transaction:" + e, e);
                  rollbackTransaction(db);
                  throw new SystemException(e.getMessage());
              }             
          }
          logger.info("Done with site nodes..");
        }
        catch(Throwable e)
        {
          statusBean.setStatus(false);
            logger.error("En error occurred when we tried to create a new siteNode:" + e.getMessage(), e);
        }
       
        updateCaches();

View Full Code Here

    public StatusBean createContents(final String principalName, final Object[] inputsArray/*List contents*/)
    {
        if(!ServerNodeController.getController().getIsIPAllowed(getRequest()))
        {
            logger.error("A client with IP " + getRequest().getRemoteAddr() + " was denied access to the webservice. Could be a hack attempt or you have just not configured the allowed IP-addresses correct.");
            return new StatusBean(false, "You are not allowed to talk to this service");
        }

    StatusBean statusBean = new StatusBean(true, "ok");

    List<Integer> newContentIdList = new ArrayList<Integer>();

        logger.info("****************************************");
        logger.info("Creating contents through webservice....");
        logger.info("****************************************");
       
        logger.info("principalName:" + principalName);
        logger.info("inputsArray:" + inputsArray);
        //logger.warn("contents:" + contents);
       
        try
        {
      final DynamicWebserviceSerializer serializer = new DynamicWebserviceSerializer();
            @SuppressWarnings("unchecked")
      List<Map<String, Object>> contents = (List<Map<String, Object>>) serializer.deserialize(inputsArray);
          logger.info("contents:" + contents);

            initializePrincipal(principalName);
          Iterator<Map<String, Object>> contentIterator = contents.iterator();
          while(contentIterator.hasNext())
          {
              //String value = (String)contentIterator.next();
              //logger.info("value:" + value);

        Map<String, Object> content = contentIterator.next();

              String name           = (String)content.get("name");
              Integer contentTypeDefinitionId = (Integer)content.get("contentTypeDefinitionId");
              Integer repositoryId       = (Integer)content.get("repositoryId");
              Integer parentContentId     = (Integer)content.get("parentContentId");
              String contentPath         = (String)content.get("contentPath");

              String creatorName         = (String)content.get("creatorName");
              Boolean isBranch         = (Boolean)content.get("isBranch");
              Integer isProtected       = (Integer)content.get("isProtected");

              Date expireDateTime = null;
              Object expireDateTimeObject = content.get("expireDateTime");
              if(expireDateTimeObject != null)
              {
                if(expireDateTimeObject instanceof Date)
                  expireDateTime = (Date)expireDateTimeObject;
                else if(expireDateTimeObject instanceof Calendar)
                  expireDateTime = ((Calendar)expireDateTimeObject).getTime();
            }               

              Date publishDateTime = null;
              Object publishDateTimeObject = content.get("publishDateTime");
              if(publishDateTimeObject != null)
              {
                if(publishDateTimeObject instanceof Date)
                  publishDateTime = (Date)publishDateTimeObject;
                else if(publishDateTimeObject instanceof Calendar)
                  publishDateTime = ((Calendar)publishDateTimeObject).getTime();
            }
             
              logger.info("name:" + name);
              logger.info("contentTypeDefinitionId:" + contentTypeDefinitionId);
              logger.info("repositoryId:" + repositoryId);
              logger.info("parentContentId:" + parentContentId);
              logger.info("contentPath:" + contentPath);
             
              if(contentPath != null && !contentPath.equals(""))
              {
                Database db = CastorDatabaseService.getDatabase();
            beginTransaction(db);
           
            try
            {
              if(parentContentId != null)
              {
                StringBuffer path = new StringBuffer();
               
                Content parentContent = ContentController.getContentController().getContentWithId(parentContentId, db);
                path.insert(0, parentContent.getName() + "/");
                while(parentContent.getParentContent() != null)
                {
                  parentContent = parentContent.getParentContent();
                  if(parentContent != null && parentContent.getParentContent() != null)
                    path.insert(0, parentContent.getName() + "/");
                }

                contentPath = path.toString() + contentPath;
              }
             
                  ContentVO parentContentVO = ContentController.getContentController().getContentVOWithPath(repositoryId, contentPath, true, this.principal, db);
                  parentContentId = parentContentVO.getId();
                 
              commitTransaction(db);
            }
            catch(Exception e)
            {
              logger.error("An error occurred so we should not complete the transaction:" + e, e);
              rollbackTransaction(db);
              throw new SystemException(e.getMessage());
            }
              }
             
               ContentVO contentVO = new ContentVO();
              contentVO.setName(name);
              contentVO.setContentTypeDefinitionId(contentTypeDefinitionId);
              contentVO.setRepositoryId(repositoryId);
              contentVO.setParentContentId(parentContentId);
             
              if(expireDateTime != null)
                contentVO.setExpireDateTime(expireDateTime);
              if(isBranch != null)
                contentVO.setIsBranch(isBranch);
              if(isProtected != null)
                  contentVO.setIsProtected(isProtected);
              if(publishDateTime != null)
                contentVO.setPublishDateTime(publishDateTime);
             
              if(creatorName != null)
                contentVO.setCreatorName(creatorName);
              else if(contentVO.getCreatorName() == null)
                  contentVO.setCreatorName(this.principal.getName());
             
              ContentVO newContentVO = contentControllerProxy.acCreate(this.principal, contentVO.getParentContentId(), contentVO.getContentTypeDefinitionId(), contentVO.getRepositoryId(), contentVO);
              if(newContentVO != null)
                statusBean.getCreatedBeans().add(new CreatedEntityBean(ContentVO.class.getName(), new Long(newContentVO.getId())));

        @SuppressWarnings("unchecked")
        List<Map<String, Object>> contentVersions = (List<Map<String, Object>>)content.get("contentVersions");
        if (contentVersions == null)
        {
          logger.info("Content had no versions. Maybe its a folder. IsBranch: " + isBranch);
        }
        else
        {
          Iterator<Map<String, Object>> contentVersionIterator = contentVersions.iterator();
          while(contentVersionIterator.hasNext())
          {
            Map<String, Object> contentVersion = contentVersionIterator.next();

            Integer languageId = (Integer)contentVersion.get("languageId");
            Integer stateId = (Integer)contentVersion.get("stateId");
            Boolean allowHTMLContent = (Boolean)contentVersion.get("allowHTMLContent");
            Boolean allowExternalLinks = (Boolean)contentVersion.get("allowExternalLinks");
            Boolean allowDollarSigns = (Boolean)contentVersion.get("allowDollarSigns");
            Boolean allowAnchorSigns = (Boolean)contentVersion.get("allowAnchorSigns");

            if(allowHTMLContent == null)
              allowHTMLContent = new Boolean(false);
            if(allowExternalLinks == null)
              allowExternalLinks = new Boolean(false);
            if(allowDollarSigns == null)
              allowDollarSigns = new Boolean(false);
            if(allowAnchorSigns == null)
              allowAnchorSigns = new Boolean(true);

            logger.info("languageId:" + languageId);
            logger.info("stateId:" + stateId);
            logger.info("allowHTMLContent:" + allowHTMLContent);
            logger.info("allowExternalLinks:" + allowExternalLinks);
            logger.info("allowDollarSigns:" + allowDollarSigns);
            logger.info("allowAnchorSigns:" + allowAnchorSigns);

            ContentVersionVO contentVersionVO = new ContentVersionVO();
            contentVersionVO.setLanguageId(languageId);

            if(contentVersionVO.getVersionModifier() == null)
              contentVersionVO.setVersionModifier(this.principal.getName());

            @SuppressWarnings("unchecked")
            Map<String, String> attributes = (Map<String, String>)contentVersion.get("contentVersionAttributes");

            DOMBuilder domBuilder = new DOMBuilder();
            Document document = domBuilder.createDocument();

            Element rootElement = domBuilder.addElement(document, "root");
            domBuilder.addAttribute(rootElement, "xmlns", "x-schema:Schema.xml");
            Element attributesRoot = domBuilder.addElement(rootElement, "attributes");

            Iterator<String> attributesIterator = attributes.keySet().iterator();
            while(attributesIterator.hasNext())
            {
              String attributeName  = attributesIterator.next();
              String attributeValue = attributes.get(attributeName);

              attributeValue = cleanAttributeValue(attributeValue, allowHTMLContent, allowExternalLinks, allowDollarSigns, allowAnchorSigns);

              Element attribute = domBuilder.addElement(attributesRoot, attributeName);
              domBuilder.addCDATAElement(attribute, attributeValue);
            }

            contentVersionVO.setVersionValue(document.asXML());

            ContentVersionVO newContentVersionVO = contentVersionControllerProxy.acCreate(this.principal, newContentVO.getId(), languageId, contentVersionVO);
            Integer newContentVersionId = newContentVersionVO.getId();
            statusBean.getCreatedBeans().add(new CreatedEntityBean(ContentVersionVO.class.getName(), new Long(newContentVersionId)));

            @SuppressWarnings("unchecked")
            List<RemoteAttachment> digitalAssets = (List<RemoteAttachment>)contentVersion.get("digitalAssets");

            logger.info("digitalAssets:" + digitalAssets);
            if(digitalAssets != null)
            {
              Iterator<RemoteAttachment> digitalAssetIterator = digitalAssets.iterator();
              while(digitalAssetIterator.hasNext())
              {
                RemoteAttachment remoteAttachment = digitalAssetIterator.next();
                logger.info("digitalAssets in ws:" + remoteAttachment);

                DigitalAssetVO newAsset = new DigitalAssetVO();
                newAsset.setAssetContentType(remoteAttachment.getContentType());
                newAsset.setAssetKey(remoteAttachment.getName());
                newAsset.setAssetFileName(remoteAttachment.getFileName());
                newAsset.setAssetFilePath(remoteAttachment.getFilePath());
                newAsset.setAssetFileSize(new Integer(new Long(remoteAttachment.getBytes().length).intValue()));
                //is = new FileInputStream(renamedFile);
                InputStream is = new ByteArrayInputStream(remoteAttachment.getBytes());

                DigitalAssetVO newDigitalAssetVO = DigitalAssetController.create(newAsset, is, newContentVersionId, principal);
                if(newDigitalAssetVO != null)
                  statusBean.getCreatedBeans().add(new CreatedEntityBean(DigitalAssetVO.class.getName(), new Long(newDigitalAssetVO.getId())));
              }
            }

            @SuppressWarnings("unchecked")
            List<String> contentCategories = (List<String>)contentVersion.get("contentCategories");

            logger.info("contentCategories:" + contentCategories);
            if(contentCategories != null)
            {
              Iterator<String> contentCategoriesIterator = contentCategories.iterator();
              while(contentCategoriesIterator.hasNext())
              {
                String contentCategoryString = contentCategoriesIterator.next();
                String[] split = contentCategoryString.split("=");
                String categoryKey = split[0];
                String fullCategoryName = split[1];
                logger.info("categoryKey:" + categoryKey);
                logger.info("fullCategoryName:" + fullCategoryName);

                CategoryVO categoryVO = CategoryController.getController().findByPath(fullCategoryName);
                logger.info("categoryVO:" + categoryVO);

                List<CategoryVO> categoryVOList = new ArrayList<CategoryVO>();
                categoryVOList.add(categoryVO);

                Database db = beginTransaction();

                try
                {
                  ContentVersion latestContentVersion = ContentVersionController.getContentVersionController().getContentVersionWithId(newContentVersionVO.getId(), db);
                  logger.info("Adding categoryKey:" + categoryKey + " to " + newContentVersionVO.getId() + ":" + categoryVO);
                  //ContentCategoryController.getController().create(categoryVOList, newContentVersionVO, categoryKey);
                  final List<Category> categories = categoryVOListToCategoryList(categoryVOList, db);
                  ContentCategoryController.getController().create(categories, latestContentVersion, categoryKey, db);

                  commitTransaction(db);
                }
                catch (Exception e)
                {
                  logger.warn("Error in contentCategory loop: " + e.getMessage(), e);
                  rollbackTransaction(db);
                  throw new SystemException(e.getMessage());
                }
              }
            }

            //Should we also change state on newly created content version?
            if(stateId != null && !stateId.equals(ContentVersionVO.WORKING_STATE))
            {
              List<EventVO> events = new ArrayList<EventVO>();
              ContentStateController.changeState(newContentVersionId, stateId, "Remote update from deliver", false, this.principal, newContentVO.getId(), events);

              if(stateId.equals(ContentVersionVO.PUBLISHED_STATE))
              {
                PublicationVO publicationVO = new PublicationVO();
                publicationVO.setName("Direct publication by " + this.principal.getName());
                publicationVO.setDescription("Direct publication from deliver");
                publicationVO.setRepositoryId(repositoryId);
                publicationVO = PublicationController.getController().createAndPublish(publicationVO, events, false, this.principal);
              }

            }
          }
        }

              @SuppressWarnings("unchecked")
        List<Map<String, Object>> accessRights = (List<Map<String, Object>>)content.get("accessRights");
              if(accessRights != null)
              {
                Iterator<Map<String, Object>> accessRightsIterator = accessRights.iterator();
                while(accessRightsIterator.hasNext())
                {
                    Map<String, Object> accessRightMap = accessRightsIterator.next();
                   
                    String interceptionPointName = (String)accessRightMap.get("interceptionPointName");
                    String parameters = (String)accessRightMap.get("parameters");
                   
                    Database db = CastorDatabaseService.getDatabase();
              beginTransaction(db);
             
              try
              {
                      InterceptionPoint interceptionPoint = InterceptionPointController.getController().getInterceptionPointWithName(interceptionPointName, db);
                     
                      logger.info("interceptionPointName:" + interceptionPointName);
                    logger.info("parameters:" + parameters);
   
                    AccessRightVO accessRightVO = new AccessRightVO();
                    accessRightVO.setParameters("" + newContentVO.getId());
                   
                    AccessRight accessRight = AccessRightController.getController().create(accessRightVO, interceptionPoint, db);
                   
              @SuppressWarnings("unchecked")
              List<String> accessRightRoles = (List<String>)accessRightMap.get("accessRightRoles");
              if(accessRightRoles != null)
                    {
                Iterator<String> accessRightRolesIterator = accessRightRoles.iterator();
                      while(accessRightRolesIterator.hasNext())
                      {
                          //Map accessRightRoleMap = (Map)accessRightRolesIterator.next();
                         
                          String roleName = accessRightRolesIterator.next();
                         
                    AccessRightRoleVO accessRightRoleVO = new AccessRightRoleVO();
                    accessRightRoleVO.setRoleName(roleName);
                    AccessRightRole accessRightRole = AccessRightController.getController().createAccessRightRole(db, accessRightRoleVO, accessRight);
                  @SuppressWarnings("unchecked")
                  Collection<AccessRightRole> roles = accessRight.getRoles();
                  roles.add(accessRightRole);
                      }
                    }

              @SuppressWarnings("unchecked")
              List<String> accessRightGroups = (List<String>)accessRightMap.get("accessRightGroups");
                    if(accessRightGroups != null)
                    {
                      Iterator<String> accessRightGroupsIterator = accessRightGroups.iterator();
                      while(accessRightGroupsIterator.hasNext())
                      {
                          String groupName = accessRightGroupsIterator.next();
                         
                    AccessRightGroupVO accessRightGroupVO = new AccessRightGroupVO();
                    accessRightGroupVO.setGroupName(groupName);
                    AccessRightGroup accessRightGroup = AccessRightController.getController().createAccessRightGroup(db, accessRightGroupVO, accessRight);
                  @SuppressWarnings("unchecked")
                  Collection<AccessRightGroup> groups = accessRight.getGroups();
                  groups.add(accessRightGroup);
                      }
                    }

              @SuppressWarnings("unchecked")
              List<String> accessRightUsers = (List<String>)accessRightMap.get("accessRightUsers");
                    if(accessRightUsers != null)
                    {
                      Iterator<String> accessRightUsersIterator = accessRightUsers.iterator();
                      while(accessRightUsersIterator.hasNext())
                      {
                          String userName = accessRightUsersIterator.next();
                         
                    AccessRightUserVO accessRightUserVO = new AccessRightUserVO();
                    accessRightUserVO.setUserName(userName);
                    AccessRightUser accessRightUser = AccessRightController.getController().createAccessRightUser(db, accessRightUserVO, accessRight);
                  @SuppressWarnings("unchecked")
                  Collection<AccessRightUser> users = accessRight.getUsers();
                  users.add(accessRightUser);
                      }
                    }

              commitTransaction(db);
            }
            catch (Exception ex)
            {
              logger.error("An error occurred so we should not complete the transaction. Message: " + ex.getMessage());
              logger.warn("An error occurred so we should not complete the transaction.", ex);
              rollbackTransaction(db);
              throw new SystemException(ex.getMessage());
            }
                }
              }
              newContentIdList.add(newContentVO.getId());
             
          }
          logger.info("Done with contents..");

        }
        catch(Throwable e)
        {
          statusBean.setStatus(false);
          statusBean.setMessage("En error occurred when we tried to create a new content:" + e.getMessage());
            logger.error("En error occurred when we tried to create a new content:" + e.getMessage());
            logger.warn("En error occurred when we tried to create a new content:" + e.getMessage(), e);
        }
       
        updateCaches();
View Full Code Here

TOP

Related Classes of org.infoglue.cms.webservices.elements.StatusBean

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.