se.vgregion.alfresco.repo.scripts.IsOrphanDocument.java Source code

Java tutorial

Introduction

Here is the source code for se.vgregion.alfresco.repo.scripts.IsOrphanDocument.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package se.vgregion.alfresco.repo.scripts;

import org.alfresco.service.cmr.repository.*;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.extensions.webscripts.*;
import org.springframework.util.Assert;
import se.vgregion.alfresco.repo.model.VgrModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author jimmie
 */
public class IsOrphanDocument extends DeclarativeWebScript implements InitializingBean {

    protected NodeService nodeService;
    private static final Logger LOG = Logger.getLogger(IsOrphanDocument.class);

    @Override
    protected Map<String, Object> executeImpl(final WebScriptRequest req, final Status status, final Cache cache) {
        Map<String, Object> model = new HashMap<String, Object>();
        final Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();

        String storeType = templateVars.get("store_type");
        String storeId = templateVars.get("store_id");
        String id = templateVars.get("id");
        StoreRef storeRef = new StoreRef(storeType, storeId);
        NodeRef nodeRef = new NodeRef(storeRef, id);

        List<AssociationRef> sourceAssocs = nodeService.getSourceAssocs(nodeRef,
                VgrModel.ASSOC_PUBLISHED_TO_STORAGE);
        String unpublishStatus = (String) nodeService.getProperty(nodeRef, VgrModel.PROP_UNPUBLISH_STATUS);

        if (sourceAssocs.isEmpty() && nodeService.hasAspect(nodeRef, VgrModel.ASPECT_PUBLISHED)
                && unpublishStatus == null) {
            model.put("isorphandocument", true);
        } else {
            model.put("isorphandocument", false);
        }

        return model;
    }

    public void setNodeService(NodeService nodeService) {
        this.nodeService = nodeService;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        Assert.notNull(nodeService);
    }
}