com.pureinfo.srm.config.workflow.function.ProductGuarder.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.srm.config.workflow.function.ProductGuarder.java

Source

/**
 * PureInfo Quake
 * @(#)ProductGuarder.java   1.0 Nov 6, 2005
 * 
 * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. 
 * All rights reserved, see the license file.
 * 
 * www.pureinfo.com.cn
 */

package com.pureinfo.srm.config.workflow.function;

import org.apache.commons.lang.StringUtils;

import com.pureinfo.ark.auth.model.IUser;
import com.pureinfo.ark.content.ArkContentHelper;
import com.pureinfo.ark.content.domain.IContentMgr;
import com.pureinfo.ark.content.model.ArkContent;
import com.pureinfo.ark.interaction.view.ViewGuarderImplBase;
import com.pureinfo.force.exception.PureException;
import com.pureinfo.srm.auth.model.SRMUser;
import com.pureinfo.srm.config.workflow.WorkflowHelper;
import com.pureinfo.srm.config.workflow.model.WfProcess;
import com.pureinfo.srm.product.model.Product;

/**
 * <P>
 * Created on Nov 6, 2005 9:33:46 PM <BR>
 * Last modified on Nov 6, 2005
 * </P>
 * 
 * @author Freeman.Hu
 * @version 1.0, Nov 6, 2005
 * @since Quake 1.0
 */
public class ProductGuarder extends ViewGuarderImplBase {
    protected boolean checkPass(ArkContent _content, IUser _user, Object[] _args) throws PureException {
        if (_args.length != 1)
            throw new PureException(PureException.INVALID_REQUEST, "args must have two arguments!");
        IContentMgr mgr = ArkContentHelper.getContentMgrOf(Product.class);
        Product product = (Product) mgr.lookupById4Edit(_content.getId());
        if ("null".equals(_args[0])) {
            WfProcess process = WorkflowHelper.getProductProcess(product.getProductForm(),
                    product.getPublicationLevel());
            return process != null ? true : false;
        }
        String[] acts = StringUtils.split((String) _args[0], "|");
        for (int i = 0; i < acts.length; i++) {
            if (WorkflowHelper.checkProductRole(product.getProductForm(), product.getPublicationLevel(), acts[i],
                    ((SRMUser) _user).getRolesList()))
                return true;
        }
        return false;
    }
}