Examples of MediumDigitalAssetImpl


Examples of org.infoglue.cms.entities.content.impl.simple.MediumDigitalAssetImpl

    if(contentVersion.getId() > contentVersionVO.getId())
    {
      selfNewVersion = contentVersion;
    }
   
    MediumDigitalAssetImpl asset = DigitalAssetController.getController().getMediumDigitalAssetWithId(digitalAssetId, db);

    Map<Integer,Integer> replaceMap = new HashMap<Integer,Integer>();
   
    List<Integer> selfContentVersionIDList = new ArrayList<Integer>();
   
    Iterator<MediumContentVersionImpl> versionIterator = asset.getContentVersions().iterator();
    while(versionIterator.hasNext())
    {
      MediumContentVersionImpl version = versionIterator.next();
      for(SmallestContentVersionVO cvVO : versions)
      {
        if(version.getContentVersionId().equals(cvVO.getId()))
        {
          logger.info("Removing from:" + cvVO.getId());
          selfContentVersionIDList.add(version.getContentVersionId());
          versionIterator.remove();
          replaceMap.put(version.getContentId(), contentId);
          break;
        }
      }
    }
    contentVersion.getDigitalAssets().add(asset);
    asset.getContentVersions().add(contentVersion);
     
    if(fixReferences)
    {
      for(Integer oldContentId : replaceMap.keySet())
      {
        Integer newContentId = replaceMap.get(oldContentId);
        logger.info("We should replace all instances of " + oldContentId + "(" + asset.getAssetKey() + ") --> " + newContentId + "(" + asset.getAssetKey() + ")");
           List<ReferenceBean> referenceBeans = RegistryController.getController().getReferencingObjectsForContentAsset(oldContentId, asset.getAssetKey(), 100, true, true, false);

           logger.info("referenceBeans:" + referenceBeans.size());
           for(Integer cvID : selfContentVersionIDList)
           {
             ContentVersionVO cvVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId(cvID, db);
            
             ReferenceBean bean = new ReferenceBean();
             ReferenceVersionBean versionBean = new ReferenceVersionBean();
             versionBean.setReferencingObject(cvVO);
             //bean.setReferencingCompletingObject(versionBean);
             bean.getVersions().add(versionBean);
             referenceBeans.add(bean);
           }
          
           logger.info("referenceBeans:" + referenceBeans.size());
           for(ReferenceBean referenceBean : referenceBeans)
           {
             logger.info("ReferenceBean:" + referenceBean.getName() + ":" + referenceBean.getReferencingCompletingObject());
               
             for(ReferenceVersionBean referenceVersionBean : referenceBean.getVersions())
             {
               Object o = referenceVersionBean.getReferencingObject();
               logger.info("o:" + o.getClass().getName());
               try
               {
                 if(o instanceof ContentVersionVO)
                 {
                   ContentVersionVO cv = (ContentVersionVO)o;
                   logger.info("Replacing in:" + cv.getId());
                      String newVersionValue = cv.getVersionValue(); //.replaceAll("\"" + oldContentId + "\"", "\"" + newContentId + "\"");
                  
                   Pattern p = Pattern.compile("<binding.*?>");
                     Matcher m = p.matcher(newVersionValue);
                     while (m.find())
                   {
                       logger.info("Found a " + m.group() + ".");
                     String binding = m.group();
                     if(binding.contains("\"" + oldContentId + "\"") && binding.contains("\"" + asset.getAssetKey() + "\""))
                     {
                       binding = binding.replaceFirst("\"" + oldContentId + "\"", "\"" + newContentId + "\"");
 
                       logger.info("Replacing:" + m.group() + ":" + binding);
                       newVersionValue = StringUtils.replace(newVersionValue, m.group(), binding);
                       //newVersionValue = newVersionValue.replaceAll(m.group(), binding);
                       logger.info("newVersionValue: " + newVersionValue);
                     }
                   }
                  
                     Pattern pInlineAssets = Pattern.compile("getInlineAssetUrl\\(.*?\\)");
                  Matcher mInlineAssets = pInlineAssets.matcher(newVersionValue);
                  while (mInlineAssets.find())
                   {
                    logger.info("Found a " + mInlineAssets.group() + ".");
                     String assetCall = mInlineAssets.group();
                     if(assetCall.contains(oldContentId + ",") && (assetCall.contains("\"" + asset.getAssetKey() + "\"") || URLDecoder.decode(assetCall, "utf-8").contains("\"" + asset.getAssetKey() + "\"")))
                     {
                       logger.info("Replacing:" + mInlineAssets.group() + ":" + assetCall);
 
                       assetCall = assetCall.replaceFirst("" + oldContentId + ",", "" + newContentId + ",");
                       newVersionValue = StringUtils.replace(newVersionValue, mInlineAssets.group(), assetCall);
                       //newVersionValue = newVersionValue.replaceAll(mInlineAssets.group(), assetCall);
                       logger.info("newVersionValue: " + newVersionValue);
                     }
                   }
                 
                   //newVersionValue = newVersionValue.replaceAll("getInlineAssetUrl\\(" + oldContentId + ",", "getInlineAssetUrl(" + newContentId + ",");
                   ContentVersion cvReal = ContentVersionController.getContentVersionController().getMediumContentVersionWithId(cv.getId(), db);
                   logger.info("cvReal:" + cvReal.getId());
                     if(selfNewVersion != null && selfNewVersion.getContentId().intValue() == cvReal.getValueObject().getContentId().intValue() && selfNewVersion.getLanguageId().intValue() == cvReal.getValueObject().getLanguageId().intValue() && selfNewVersion.getId().intValue() > cvReal.getId().intValue())
                     {
                       logger.info("Was itself - lets use the new version instead...");
                       cvReal = selfNewVersion;
                     }

                   cvReal.setVersionValue(newVersionValue);
                   cvReal.setVersionComment("Asset moved...");
                   cvReal.setVersionModifier(principal.getName());
                   cvReal.setModifiedDateTime(new Date());
 
                   RegistryController.getController().updateContentVersion(cvReal.getValueObject(), null, db);
                 }
                 else if(o instanceof SiteNodeVersionVO)
                 {
                   SiteNodeVersionVO snvo = (SiteNodeVersionVO)o;
                   logger.info("Replacing in sn:" + snvo.getId());
                  
                           SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(snvo.getSiteNodeId(), db);
                     LanguageVO masterLanguageVO = LanguageController.getController().getMasterLanguage(siteNodeVO.getRepositoryId(), db);
                     ContentVersionVO cv = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(siteNodeVO.getMetaInfoContentId(), masterLanguageVO.getId(), db);
                     logger.info("Replacing in:" + cv.getVersionValue());
                  
                   String newVersionValue = cv.getVersionValue(); //.replaceAll("\"" + oldContentId + "\"", "\"" + newContentId + "\"");
                  
                   Pattern p = Pattern.compile("<binding.*?>");
                     Matcher m = p.matcher(newVersionValue);
                     while (m.find())
                   {
                       logger.info("Found a " + m.group() + ".");
                     String binding = m.group();
                     if(binding.contains("\"" + oldContentId + "\"") && binding.contains("\"" + asset.getAssetKey() + "\""))
                     {
                       binding = binding.replaceFirst("\"" + oldContentId + "\"", "\"" + newContentId + "\"");
 
                       logger.info("Replacing:" + m.group() + ":" + binding);
                       newVersionValue = StringUtils.replace(newVersionValue, m.group(), binding);
View Full Code Here

Examples of org.infoglue.cms.entities.content.impl.simple.MediumDigitalAssetImpl

   
    Collection contentVersions = new ArrayList();
    contentVersions.add(contentVersion);
    logger.info("Added contentVersion:" + contentVersion.getId());
 
    digitalAsset = new MediumDigitalAssetImpl();
    digitalAsset.setValueObject(digitalAssetVO.createCopy());
    if(CmsPropertyHandler.getEnableDiskAssets().equals("false"))
      digitalAsset.setAssetBlob(is);
    digitalAsset.setContentVersions(contentVersions);
   
View Full Code Here

Examples of org.infoglue.cms.entities.content.impl.simple.MediumDigitalAssetImpl

      //ContentVersion contentVersion = ContentVersionController.getContentVersionController().getContentVersionWithId(newContentVersionId, db);

      if(assetIdMap.containsKey(oldDigitalAsset.getId()))
      {
        logger.info("The asset was allready copied by another version - let's just connect the new one");
        MediumDigitalAssetImpl newDigitalAsset = getMediumDigitalAssetWithId(assetIdMap.get(oldDigitalAsset.getId()), db);
        newDigitalAsset.getContentVersions().add(cv);
      }
      else
      {
        Collection contentVersions = new ArrayList();
        contentVersions.add(cv);

        try
        {
          String filePath = getDigitalAssetFilePath(oldDigitalAsset.getValueObject(), db);
          File oldAssetFile = new File(filePath);
         
          logger.info("Creating asset for:" + oldDigitalAsset.getAssetKey() + ":" + oldContentVersion.getId() + "/" + cv.getId());
          DigitalAssetVO digitalAssetVO = new DigitalAssetVO();
          digitalAssetVO.setAssetContentType(oldDigitalAsset.getAssetContentType());
          digitalAssetVO.setAssetFileName(oldDigitalAsset.getAssetFileName());
          digitalAssetVO.setAssetFilePath(oldDigitalAsset.getAssetFilePath());
          digitalAssetVO.setAssetFileSize(oldDigitalAsset.getAssetFileSize());
          digitalAssetVO.setAssetKey(oldDigitalAsset.getAssetKey());
         
          DigitalAsset digitalAsset = new MediumDigitalAssetImpl();
          digitalAsset.setValueObject(digitalAssetVO);
 
          if(oldAssetFile.exists())
          {
            InputStream is = new FileInputStream(oldAssetFile);
   
            if(is != null)
            {
              digitalAsset.setAssetBlob(is);
            }
            else
              digitalAsset.setAssetBlob(null);
            //digitalAsset.setAssetBlob(oldDigitalAsset.getAssetBlob());
          }
          else
          {
            logger.warn("No asset file found:" + oldAssetFile.getPath());
            digitalAsset.setAssetBlob(null);
          }
         
          db.create(digitalAsset);
         
          assetIdMap.put(oldDigitalAsset.getId(), digitalAsset.getId());
          digitalAsset.setContentVersions(contentVersions);
        }
        catch(Exception e)
        {
          logger.error("An error occurred when we tried to copy asset:" + e.getMessage());
          logger.warn("An error occurred when we tried to copy asset:" + e.getMessage(), e);
View Full Code Here

Examples of org.infoglue.cms.entities.content.impl.simple.MediumDigitalAssetImpl

          int i = 0;
      while (results.hasMore() && i < assetNumberLimit)
            {
        boolean keep = true;
             
              MediumDigitalAssetImpl digitalAsset = (MediumDigitalAssetImpl)results.next();
              if(digitalAsset.getAssetKey().equals("portletentityregistry.xml"))
                keep = false;
             
              Collection contentVersions = digitalAsset.getContentVersions();
              Iterator contentVersionsIterator = contentVersions.iterator();
              ContentVersion contentVersion = null;
              while(contentVersionsIterator.hasNext())
              {
                contentVersion = (ContentVersion)contentVersionsIterator.next();
                if(!isOldVersion(contentVersion, numberOfVersionsToKeep))
                  keep = false;
              }
             
              if(contentVersion != null && keep)
              {
                if(contentVersion.getOwningContent() != null)
                {
                  String contentPath = ContentController.getContentController().getContentPath(contentVersion.getOwningContent().getId(), true, true);
                  optimizationBeanList.addDigitalAsset(digitalAsset);
                  optimizationBeanList.addEventVersions(toVOList(contentVersions));
                  optimizationBeanList.setContentPath(digitalAsset.getId(), contentPath);
                  i++;
                }
                else
                {
                  logger.error("ContentVersion with id:" + contentVersion.getId() + " had no ownningcontent");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.