protected String getParentFormName() {
   final AVMService avmService = this.getServiceRegistry().getAVMService();
   return avmService
       .getNodeProperty(
           AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(),
           AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(),
           WCMAppModel.PROP_PARENT_FORM_NAME)
       .getStringValue();
 }
  /**
   * @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
   */
  public boolean evaluate(final Node node) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    AVMService avmService = Repository.getServiceRegistry(facesContext).getAVMService();

    Pair<Integer, String> p = AVMNodeConverter.ToAVMVersionPath(node.getNodeRef());
    AVMNodeDescriptor nodeDesc = avmService.lookup(-1, p.getSecond());

    // don't allow action if its a 'layeredfolder' and a primary indirection
    return !(nodeDesc.getType() == AVMNodeType.LAYERED_DIRECTORY && nodeDesc.isPrimary());
  }
 /* package */ FormInstanceDataImpl(final NodeRef nodeRef, final FormsService formsService) {
   if (nodeRef == null) {
     throw new NullPointerException();
   }
   if (formsService == null) {
     throw new NullPointerException();
   }
   final AVMService avmService = this.getServiceRegistry().getAVMService();
   if (!avmService.hasAspect(
       AVMNodeConverter.ToAVMVersionPath(nodeRef).getFirst(),
       AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond(),
       WCMAppModel.ASPECT_FORM_INSTANCE_DATA)) {
     throw new IllegalArgumentException(
         "node " + nodeRef + " does not have aspect " + WCMAppModel.ASPECT_FORM_INSTANCE_DATA);
   }
   this.nodeRef = nodeRef;
   this.formsService = formsService;
 }
 public List<Rendition> getRenditions(boolean includeDeleted) {
   final AVMService avmService = this.getServiceRegistry().getAVMLockingAwareService();
   final PropertyValue pv =
       avmService.getNodeProperty(-1, this.getPath(), WCMAppModel.PROP_RENDITIONS);
   final Collection<Serializable> renditionPaths =
       (pv == null ? Collections.EMPTY_LIST : pv.getCollection(DataTypeDefinition.TEXT));
   final String storeName = AVMUtil.getStoreName(this.getPath());
   final List<Rendition> result = new ArrayList<Rendition>(renditionPaths.size());
   for (Serializable path : renditionPaths) {
     String avmRenditionPath = AVMUtil.buildAVMPath(storeName, (String) path);
     if (avmService.lookup(-1, avmRenditionPath, includeDeleted) == null) {
       if (logger.isDebugEnabled()) {
         logger.debug("ignoring dangling rendition at: " + avmRenditionPath);
       }
     } else {
       final Rendition r = new RenditionImpl(-1, avmRenditionPath, this.getFormsService());
       try {
         if (!this.equals(r.getPrimaryFormInstanceData(includeDeleted))) {
           if (logger.isDebugEnabled()) {
             logger.debug(
                 "rendition "
                     + r
                     + " points at form instance data "
                     + r.getPrimaryFormInstanceData(includeDeleted)
                     + " instead of "
                     + this
                     + ". Not including in renditions list.");
           }
           continue;
         }
       } catch (FileNotFoundException fnfe) {
         continue;
       }
       if (r.getRenderingEngineTemplate() != null) {
         result.add(r);
       }
     }
   }
   return result;
 }
 @Override
 protected List<StoreRef> getAllStores() {
   List<AVMStoreDescriptor> stores = avmService.getStores();
   List<StoreRef> storeRefs = new ArrayList<StoreRef>(stores.size());
   for (AVMStoreDescriptor storeDesc : stores) {
     StoreRef storeRef = AVMNodeConverter.ToStoreRef(storeDesc.getName());
     if (avmSnapShotTriggeredIndexingMethodInterceptor.getIndexMode(storeRef.getIdentifier())
         == IndexMode.UNINDEXED) {
       // ALF-5722 fix
       continue;
     }
     storeRefs.add(storeRef);
   }
   return storeRefs;
 }
  public List<FormInstanceData.RegenerateResult> regenerateRenditions()
      throws FormNotFoundException {
    if (logger.isDebugEnabled()) {
      logger.debug("regenerating renditions of " + this);
    }

    AVMLockingService avmLockService = this.getServiceRegistry().getAVMLockingService();
    final AVMService avmService = this.getServiceRegistry().getAVMService();
    PropertyValue pv =
        avmService.getNodeProperty(
            AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(),
            AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(),
            WCMAppModel.PROP_ORIGINAL_PARENT_PATH);

    String originalParentAvmPath =
        (pv == null) ? AVMNodeConverter.SplitBase(this.getPath())[0] : pv.getStringValue();

    final HashSet<RenderingEngineTemplate> allRets =
        new HashSet<RenderingEngineTemplate>(this.getForm().getRenderingEngineTemplates());
    final List<RegenerateResult> result = new LinkedList<RegenerateResult>();
    // regenerate existing renditions
    boolean renditionLockedBefore = false;
    String path = null;

    for (final Rendition r : this.getRenditions()) {
      // Try to skip renditions without rendering engine template.
      if (r instanceof RenditionImpl) {
        RenditionImpl rImpl = (RenditionImpl) r;
        RenderingEngineTemplate ret = rImpl.getRenderingEngineTemplate();
        if ((ret != null) && (ret instanceof RenderingEngineTemplateImpl)) {
          RenderingEngineTemplateImpl retImpl = (RenderingEngineTemplateImpl) ret;
          if (!retImpl.isExists()) {
            continue;
          }
        }
      }
      final RenderingEngineTemplate ret = r.getRenderingEngineTemplate();
      if (ret == null || !allRets.contains(ret)) {
        continue;
      }
      try {
        if (logger.isDebugEnabled()) {
          logger.debug("regenerating rendition " + r + " using template " + ret);
        }

        renditionLockedBefore = false;
        path = r.getPath();
        AVMLock lock =
            avmLockService.getLock(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path));
        if (lock != null) {
          renditionLockedBefore = true;

          if (logger.isDebugEnabled()) {
            logger.debug("Lock already exists for " + path);
          }
        }

        ret.render(this, r);
        allRets.remove(ret);
        result.add(new RegenerateResult(ret, path, r));
      } catch (Exception e) {
        result.add(new RegenerateResult(ret, path, e));

        // remove lock if there wasn't one before
        if (renditionLockedBefore == false) {
          avmLockService.removeLock(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path));

          if (logger.isDebugEnabled()) {
            logger.debug("Removed lock for " + path + " as it failed to generate");
          }
        }
      }
    }

    // render all renditions for newly added templates
    for (final RenderingEngineTemplate ret : allRets) {
      try {
        renditionLockedBefore = false;
        path = ret.getOutputPathForRendition(this, originalParentAvmPath, getName());

        if (logger.isDebugEnabled()) {
          logger.debug(
              "regenerating rendition of "
                  + this.getPath()
                  + " at "
                  + path
                  + " using template "
                  + ret);
        }

        AVMLock lock =
            avmLockService.getLock(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path));
        if (lock != null) {
          renditionLockedBefore = true;

          if (logger.isDebugEnabled()) {
            logger.debug("Lock already exists for " + path);
          }
        }

        result.add(new RegenerateResult(ret, path, ret.render(this, path)));
      } catch (Exception e) {
        result.add(new RegenerateResult(ret, path, e));

        // remove lock if there wasn't one before
        if (renditionLockedBefore == false) {
          avmLockService.removeLock(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path));

          if (logger.isDebugEnabled()) {
            logger.debug("Removed lock for " + path + " as it failed to generate");
          }
        }
      }
    }
    return result;
  }