Teamcenter 产品配置前操作代码

 
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.apache.log4j.Logger;

import com.cfg0.services.internal.strong.configurator.ConfiguratorManagementService;
import com.cfg0.services.internal.strong.configurator._2015_10.ConfiguratorManagement.ApplicationConfigExpression;
import com.cfg0.services.internal.strong.configurator._2015_10.ConfiguratorManagement.BusinessObjectConfigExpression;
import com.cfg0.services.internal.strong.configurator._2015_10.ConfiguratorManagement.ConfigExpression;
import com.cfg0.services.internal.strong.configurator._2015_10.ConfiguratorManagement.ConfigExpressionGroup;
import com.cfg0.services.internal.strong.configurator._2015_10.ConfiguratorManagement.ConfigExpressionSet;
import com.cfg0.services.internal.strong.configurator._2015_10.ConfiguratorManagement.ConfigExpressionTerm;
import com.cfg0.services.internal.strong.configurator._2015_10.ConfiguratorManagement.ConfigSubExpression;
import com.cfg0.services.internal.strong.configurator._2015_10.ConfiguratorManagement.ConvertVariantExpressionInput;
import com.cfg0.services.internal.strong.configurator._2015_10.ConfiguratorManagement.ConvertVariantExpressionsResponse;
import com.cfg0.services.internal.strong.configurator._2015_10.ConfiguratorManagement.SetVariantExpressionInput;
import com.real.session.cfg.BaseSession;
import com.real.session.manager.RealSessionManager;
import com.sotos.uif.exception.TCOperationException;
import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException;
import com.teamcenter.services.internal.strong.core.ICTService;
import com.teamcenter.services.internal.strong.core._2011_06.ICT;
import com.teamcenter.services.internal.strong.core._2011_06.ICT.Arg;
import com.teamcenter.services.internal.strong.core._2011_06.ICT.Entry;
import com.teamcenter.services.strong.core.DataManagementService;
import com.teamcenter.services.strong.core._2007_01.DataManagement.VecStruct;
import com.teamcenter.services.strong.core._2008_06.DataManagement.CreateIn;
import com.teamcenter.services.strong.core._2008_06.DataManagement.CreateInput;
import com.teamcenter.services.strong.core._2008_06.DataManagement.CreateOut;
import com.teamcenter.services.strong.core._2008_06.DataManagement.CreateResponse;
import com.teamcenter.soa.client.model.ModelObject;
import com.teamcenter.soa.client.model.ServiceData;
import com.teamcenter.soa.client.model.Type;
import com.teamcenter.soa.client.model.strong.Cfg0AbsFamily;
import com.teamcenter.soa.client.model.strong.Cfg0AbsValue;
import com.teamcenter.soa.client.model.strong.Cfg0ConfiguratorPerspective;
import com.teamcenter.soa.client.model.strong.RevisionRule;
import com.teamcenter.soa.exceptions.NotLoadedException;

public class ConfigurationOperation {

    static Logger logger = Logger.getLogger(ConfigurationOperation.class);
    /*public static void main(String[] args) {
        ModelObject dictionary = TcUtil.getModelObjectByUid("g6Z9sVFy4TQ6oA");
        ModelObject family = TcUtil.getModelObjectByUid("w1b9spRf4TQ6oA");
        try {
            //createFamily(dictionary,familygroup,"Fam6","CustFam5");
            //createFamilies(dictionary, familygroup, new String[]{"Famqq5","Famqq6"}, new String[]{"CustFam9","CustFam10"});
            //createOptionValue(dictionary,family,"V2","V1Desc");
            createOptionValues(dictionary,family,new String[]{"V3","V4"},new String[]{"V3Desc","V4Desc"});
        } catch (ServiceException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }*/
   
    public BaseSession tcSession = null;
    public TCTools tool;
    public ConfigurationOperation(BaseSession tcSession){
        this.tcSession = tcSession;
        tool = new TCTools(tcSession);
    }
   
    public static void main(String[] args) {
//      try {
//          ModelObject queryFamilyGroup = queryFamilyGroup("TestBatch1W");
//          logger.info(queryFamilyGroup);
//          ModelObject queryFamily = queryFamily("Famqq5W");
//          logger.info(queryFamily);
//          ModelObject queryOptionValue = queryOptionValue("ER4W");
//          logger.info(queryOptionValue);
//      } catch (TCOperationException e) {
//          // TODO Auto-generated catch block
//          e.printStackTrace();
//      }
        /*try {
            createConfigurationContext("VDL010","CVTest","CVDesc");
        } catch (ServiceException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }*/
       
//      ModelObject cc = TcUtil.getModelObjectByUid("Q9Z9N9pS4TQ6oA");
//      ModelObject queryFamilyGroup;
//      try {
//          queryFamilyGroup = queryFamilyGroup("Safety");
//          //queryFamilyGroup = queryOptionValue("V2");
//          updateObjecttoConfigurationContext(cc,queryFamilyGroup);
//      } catch (TCOperationException e) {
//          // TODO Auto-generated catch block
//          e.printStackTrace();
//      } catch (ServiceException e) {
//          // TODO Auto-generated catch block
//          e.printStackTrace();
//      }
       
//      try {
//          removeObjectfromConfigurationContext("VDL010","Safety");
//      } catch (TCOperationException e) {
//          // TODO Auto-generated catch block
//          e.printStackTrace();
//      } catch (ServiceException e) {
//          // TODO Auto-generated catch block
//          e.printStackTrace();
//      }
       
       
       
        /*ModelObject cfgcontext  =  TcUtil.getModelObjectByUid("Q9Z9N9pS4TQ6oA");
        if(cfgcontext != null){
            try {
                ModelObject newSVR = createSVR("testsvr", "testsvrdesc", cfgcontext);
                Map<ModelObject,ModelObject> family_option_valus_map = new HashMap<ModelObject,ModelObject>();
                ModelObject family = queryFamily("BX");
                ModelObject option_value = queryOptionValue("BX01");
               
                ModelObject family1 = queryFamily("Famqq6");
                ModelObject option_value1 = queryOptionValue("V1");
               
                family_option_valus_map.put(family,option_value);
                family_option_valus_map.put(family1,option_value1);
               
                createSVRBasedOnOptions(newSVR, family_option_valus_map);
            } catch (ServiceException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (TCOperationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }*/
        /*try {
            ModelObject configuremodelObject = TcUtil.getModelObjectByUid("Q9Z9N9pS4TQ6oA");
            ModelObject perspective = TcUtil.getModelObjectPropertyValue(configuremodelObject, "cfg0ConfigPerspective");
            Map<ModelObject,ModelObject> family_option_valus_map = new HashMap<ModelObject,ModelObject>();
           
            ModelObject family = TcUtil.getModelObjectByUid("xkbtm2RK4TQ6oA");
            ModelObject option_value = TcUtil.getModelObjectByUid("RWZtGDpB4TQ6oA");
           
            ModelObject family1 = TcUtil.getModelObjectByUid("w1b9spRf4TQ6oA");
            ModelObject option_value1 = TcUtil.getModelObjectByUid("w9Y9spRf4TQ6oA");
           
            family_option_valus_map.put(family,option_value);
            family_option_valus_map.put(family1,option_value1);
           
            String formula = getExpressionBasedOnConfig(perspective, family_option_valus_map);
            System.out.println("formula is "+formula);
            TCBOMUitl bomutil = new TCBOMUitl();
            ModelObject ir = TcUtil.getModelObjectByUid("A7e98eDC4TQ6oA");
            bomutil.createBOMWindowWithIR(ir);
            try {
                TcUtil.loadObjectProperties(bomutil.getTopline(), new String[]{"bl_all_child_lines","bl_has_children"});
                if(bomutil.getTopline().get_bl_has_children()){
                    ModelObject[] childrens = bomutil.getTopline().get_bl_all_child_lines();
                    for (int i = 0; i < childrens.length; i++) {
                        TcUtil.setPropertyStringValue(childrens[i], "bl_formula", formula);
                    }
                   
                }
            } catch (NotLoadedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            bomutil.saveBOMWindow();
            bomutil.closeBOMWindow();
        } catch (TCOperationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }*/
//      try {
//          TcSession_1 session = new TcSession_1();
//          ConfigurationOperation cfgOp = new ConfigurationOperation(session);
//          cfgOp.createConfigurationContext("","CVTest22","CVDesc");
//      } catch (ServiceException e) {
//      // TODO Auto-generated catch block
//      e.printStackTrace();
//      }
       
    }
    public static final String QUERY_FAMILY_GROUP = "__FamilyGroup";//根据familygroup的ID只查询familygroup
    public static final String QUERY_FAMILY_GROUP_WITH_DICTIONARY = "__FamilyGroup";//根据familygroup的ID以及Dictionary的ID查询familygroup
   
    public static final String QUERY_FAMILY = "__Cfg0Families";//根据family的ID只查询family
    public static final String QUERY_FAMILY_WITH_DICTIONARY = "__Cfg0OptionFamiliesFromIDs";//根据family的ID以及Dictionary的ID只查询family
   
    public static final String QUERY_OPTION_VALUE = "__Cfg0OptionValuesFromValueIDs";
    public static final String QUERY_OPTION_VALUE_WITH_DICTIONARY = "__Cfg0OptionValuesFromValueIDs";//根据optionvalue的ID以及Dictionary的ID只查询选项值
   
    public static final String QUERY_OPTION_VALUE_WITH_FAMILY = "__Cfg0OptionValuesFromOptionFamilyIDs";//根据选项的ID以及Dictionary的ID只查询选项值
   
    public static final String QUERY_ALLOCATION_VALUE = "__Cfg0GetAllocationForProduct_CV";//根据配置器关联的ID以及Allocation的名称只查询Allocation
   
    public static final String QUERY_CONFIGURATION_CONTEXT_VALUE = "__Configuration_Item_Name_or_ID";//根据配置器关联的ID以及Allocation的名称只查询Allocation
   
    /**
     * 转换变量表达式
     * @param perspective
     * @param family_optionsvaluesmap 选项/选项值键值对,仅仅可以用于OR
     */
    public  String getExpressionBasedOnConfig(ModelObject perspective,Map<ModelObject,ModelObject> family_optionsvaluesmap){
        ConfiguratorManagementService configservice = ConfiguratorManagementService.getService(this.tcSession.getConnection());
        //configservice.getAdmissibility
       
        SetVariantExpressionInput[] paramArrayOfSetVariantExpressionInput = null;
        RevisionRule paramRevisionRule = null;
        paramArrayOfSetVariantExpressionInput[0].saveExpressions = true;
        configservice.setVariantExpressions(paramArrayOfSetVariantExpressionInput, paramRevisionRule);
       
        ConvertVariantExpressionInput[]  inputs = new ConvertVariantExpressionInput[1];
        ConvertVariantExpressionInput input = new ConvertVariantExpressionInput();
        inputs[0] = input;
       
        ApplicationConfigExpression[] configexpressions = new ApplicationConfigExpression[1];
        ApplicationConfigExpression configexpression = new ApplicationConfigExpression();
        configexpressions[0] = configexpression;
       
       
        ConfigExpressionSet[] sets = new ConfigExpressionSet[1];
        ConfigExpressionSet set = new ConfigExpressionSet();
       
       
        ConfigExpression[] ces = new ConfigExpression[1];
        ConfigExpression ce = new ConfigExpression();
        ces[0] = ce;
       
        ConfigSubExpression[] subexpressions = new ConfigSubExpression[1];
        ConfigSubExpression subexpression = new ConfigSubExpression();
        subexpressions[0] = subexpression;
       
        /**
         * 一组内部表示其关系是OR关系
         * 组与组之间表示的是AND关系,其中可以通过复杂组合进行group的封装
         * OperationCode 5 表示等于
         * OperationCode 6 表示不等于
         */
        ConfigExpressionGroup[] groups = null;
        if(family_optionsvaluesmap.size() > 0){
            groups = new ConfigExpressionGroup[family_optionsvaluesmap.size()];
            Set keySet = family_optionsvaluesmap.keySet();
            Iterator itr = keySet.iterator();
            int count = 0;
            while(itr.hasNext()){
               
                ModelObject family = (ModelObject) itr.next();
                ModelObject option_value = family_optionsvaluesmap.get(family);
                String familyID = tool.getCommonPropertyValue(family, "cfg0ObjectId");
                String valueText = tool.getCommonPropertyValue(option_value, "cfg0ObjectId");
               
                ConfigExpressionTerm[] terms = new ConfigExpressionTerm[1];
                ConfigExpressionTerm term = new ConfigExpressionTerm();
                terms[0] = term;
               
                term.familyID = familyID;
                term.familyNamespace = "Teamcenter";
                term.operatorCode = 5;
                term.valueText = valueText;
               
                groups[count] = new ConfigExpressionGroup();
                groups[count].groupName ="";
                groups[count].terms = terms;
               
                count++;
            }
        }
       
        subexpression.expressionGroups  = groups;
       
        ce.clientID ="";
        ce.expressionType = 23;
        ce.formula = "";
        ce.subExpressions = subexpressions;
               
        set.configExpressions = ces;
       
        configexpression.exprID="";
        configexpression.expressionType = 23;
        configexpression.formula = "";
        configexpression.configExprSets = sets;
       
        input.clientId = "";
        input.expressionFormat = 0;
        input.exprsToConvert = configexpressions;
        Type typeObjectperspective = perspective.getTypeObject();
        Cfg0ConfiguratorPerspective persptcive_temp = new  Cfg0ConfiguratorPerspective(typeObjectperspective, perspective.getUid());
        input.context = persptcive_temp;//perspective
        ConvertVariantExpressionsResponse convertVariantExpressions = configservice.convertVariantExpressions(inputs);
        String formula = convertVariantExpressions.outputs[0].applConfigExprsWithDisplayString[0].applConfigExpr.formula;
       
        return formula;
    }
    /**
     * 构建SVR变量表达式
     * @param svr
     * @param family_optionsvaluesmap
     */
    public  void createSVRBasedOnOptions(ModelObject svr,Map<ModelObject,ModelObject> family_optionsvaluesmap){
        ConfiguratorManagementService configservice = ConfiguratorManagementService.getService(this.tcSession.getConnection());
        SetVariantExpressionInput[]  inputs = new SetVariantExpressionInput[1];
        SetVariantExpressionInput input = new SetVariantExpressionInput();
        inputs[0] = input;
       
       
        ApplicationConfigExpression[] configexpressions = new ApplicationConfigExpression[1];
        ApplicationConfigExpression configexpression = new ApplicationConfigExpression();
        configexpressions[0] = configexpression;
       
        ConfigExpressionSet[] sets = new ConfigExpressionSet[1];
        ConfigExpressionSet set = new ConfigExpressionSet();
        sets[0] = set;
       
       
        ConfigExpression[] ces = new ConfigExpression[1];
        ConfigExpression ce = new ConfigExpression();
        ces[0] = ce;
       
        ConfigSubExpression[] subexpressions = new ConfigSubExpression[1];
        ConfigSubExpression subexpression = new ConfigSubExpression();
        subexpressions[0] = subexpression;
       
        ConfigExpressionGroup[] groups = null;
        if(family_optionsvaluesmap.size() > 0){
            groups = new ConfigExpressionGroup[family_optionsvaluesmap.size()];
            Set keySet = family_optionsvaluesmap.keySet();
            Iterator itr = keySet.iterator();
            int count = 0;
            while(itr.hasNext()){
               
                ModelObject family = (ModelObject) itr.next();
                ModelObject option_value = family_optionsvaluesmap.get(family);
                String familyID = tool.getCommonPropertyValue(family, "cfg0ObjectId");
                String valueText = tool.getCommonPropertyValue(option_value, "cfg0ObjectId");
//              System.out.println("set family"+familyID + "to:"+valueText);
                ConfigExpressionTerm[] terms = new ConfigExpressionTerm[1];
                ConfigExpressionTerm term = new ConfigExpressionTerm();
                terms[0] = term;
               
                Type typeObjectfamily = family.getTypeObject();
                Cfg0AbsFamily absFamily = new Cfg0AbsFamily(typeObjectfamily,family.getUid());
                Type typeObjecttoption = option_value.getTypeObject();
                Cfg0AbsValue absOption = new Cfg0AbsValue(typeObjecttoption,option_value.getUid());
               
                term.family = absFamily;
                term.value = absOption;
                term.familyID = familyID;
                term.familyNamespace = "Teamcenter";
                term.operatorCode = 5;
                term.valueText = valueText;
               
                groups[count] = new ConfigExpressionGroup();
                groups[count].groupName ="";
                groups[count].terms = terms;
               
                count++;
            }
        }
       
        subexpression.expressionGroups  = groups;
       
        ce.clientID ="";
        ce.expressionType = 18;
        ce.formula = "";
        ce.subExpressions = subexpressions;
               
        set.configExpressions = ces;
       
        configexpression.exprID="";
        configexpression.expressionType = 18;
        configexpression.formula = "";
        configexpression.configExprSets = sets;
       
        BusinessObjectConfigExpression[] businessobjectConfiexpressions = new BusinessObjectConfigExpression[1];
        BusinessObjectConfigExpression businessobjectConfiexpression = new BusinessObjectConfigExpression();
        businessobjectConfiexpressions[0] = businessobjectConfiexpression;
        businessobjectConfiexpression.targetObject = svr;
        businessobjectConfiexpression.clientId  = svr.getUid();
        businessobjectConfiexpression.expressions = configexpressions;
       
       
        input.saveExpressions = true;
        input.businessObjectExpressions = businessobjectConfiexpressions;
        ServiceData setVariantExpressions = configservice.setVariantExpressions(inputs, null);
        if(setVariantExpressions.sizeOfPartialErrors()>0){
            logger.error("构建SVR错误,错误信息为:"+setVariantExpressions.getPartialError(0));
        }else{
            logger.info("构建SVR成功");
        }
    }
    /**
     * 创建SVR并将其挂在配置器关联下
     * @param svrname
     * @param svrdesc
     * @return
     * @throws ServiceException
     * @throws TCOperationException
     */
    public  ModelObject createSVR(String svrname,String svrdesc,ModelObject configurationcontext) throws ServiceException, TCOperationException{
        CreateIn[] inputs = new CreateIn[1];
       
        CreateIn input  = new CreateIn();
        inputs[0]  = input ;
       
        Map<String,String> base_string_properties = new HashMap<String,String>();
        base_string_properties.put("object_name", svrname);
        base_string_properties.put("object_desc", svrdesc);
       
        input.data.boName = "VariantRule";
        input.data.stringProps = base_string_properties;
        //create
        DataManagementService datamanagementservice = DataManagementService.getService(this.tcSession.getConnection());
        CreateResponse response = datamanagementservice.createObjects(inputs);
        ModelObject svr = response.output[0].objects[0];
        if(svr != null){
            logger.error("创建SVR成功");
            if(configurationcontext != null){
                tool.createRelationships(configurationcontext, new ModelObject[]{svr}, "IMAN_reference");
                logger.error("SVR成功添加到配置器关联下");
            }else{
                logger.error("SVR未添加到配置器关联下");
            }
        }
        else{
            logger.error("创建SVR失败");
        }
        return svr;
    }
    /**
     * 批量创建SVR,并且将其挂在配置器关联对象下
     * @param svrname
     * @param svrdesc
     * @return
     * @throws ServiceException
     * @throws TCOperationException
     */
    public  ModelObject[] createSVRS(String[] svrname,String svrdesc[],ModelObject configurationcontext) throws ServiceException, TCOperationException{
        ModelObject[] svrs = null;
        if(svrname!= null && svrname.length > 0){
            CreateIn[] inputs = new CreateIn[svrname.length];
            for (int i = 0; i < svrname.length; i++) {
                CreateIn input  = new CreateIn();
                inputs[i]  = input ;
                Map<String,String> base_string_properties = new HashMap<String,String>();
                base_string_properties.put("object_name", svrname[i]);
                base_string_properties.put("object_desc", svrdesc[i]);
                input.data.boName = "VariantRule";
                input.data.stringProps = base_string_properties;
            }
            //create
            DataManagementService datamanagementservice = DataManagementService.getService(this.tcSession.getConnection());
            CreateResponse response = datamanagementservice.createObjects(inputs);
            svrs = response.output[0].objects;
            if(svrs != null){
                logger.error("创建SVR成功");
                if(configurationcontext != null){
                    tool.createRelationships(configurationcontext,svrs, "IMAN_reference");
                    logger.error("SVR成功添加到配置器关联下");
                }else{
                    logger.error("SVR未添加到配置器关联下");
                }
            }
            else{
                logger.error("创建SVR失败");
            }
        }
        return svrs;
    }
    /**
     * 查询组族
     * @param familyGroupid
     * @throws TCOperationException
     */
    public  ModelObject[] queryFamilyGroup(String familyGroupid) throws TCOperationException{
        Map<String,String> criterias = new HashMap<String,String>();
        criterias.put("Cfg0AbsFamilyGroupThread:wso_thread.fnd0ThreadId", familyGroupid);
        ModelObject[] familgroups = tool.queryObjectsBySavedQuery(QUERY_FAMILY_GROUP, criterias);
        return familgroups;
    }
    /**
     * 查询组族
     * @param familyGroupid
     * @throws TCOperationException
     */
    public  ModelObject[] queryFamilyGroup(String familyGroupid,String dictionary) throws TCOperationException{
        Map<String,String> criterias = new HashMap<String,String>();
        criterias.put("Cfg0AbsFamilyGroupThread:wso_thread.fnd0ThreadId", familyGroupid);
        ModelObject[] familgroups = tool.queryObjectsBySavedQuery(QUERY_FAMILY_GROUP, criterias);
        return familgroups;
    }
    /**
     * 查询族
     * @param familyid
     * @throws TCOperationException
     */
    public  ModelObject[] queryFamily(String familyid) throws TCOperationException{
        Map<String,String> criterias = new HashMap<String,String>();
        criterias.put("Cfg0AbsFamilyThread:wso_thread.fnd0ThreadId", familyid);
        ModelObject[] famils = tool.queryObjectsBySavedQuery(QUERY_FAMILY, criterias);
        return famils;
    }
    /**
     * 根据ID或者名称查询配置器关联
     * @param id
     * @param name
     * @return
     * @throws TCOperationException
     */
    public  ModelObject queryConfigurationContext(String id,String name) throws TCOperationException{
        Map<String,String> criterias = new HashMap<String,String>();
        criterias.put("item_id", id);
        criterias.put("object_name", name);
        ModelObject[] configuration = tool.queryObjectsBySavedQuery(QUERY_CONFIGURATION_CONTEXT_VALUE, criterias);
        if (configuration != null && configuration.length > 0 ) {
            return configuration[0];
        }
        else{
            return null;
        }
    }
    /**
     * 查询选项值
     * @param familyid
     * @throws TCOperationException
     */
    public  ModelObject[] queryOptionValue(String optionvalueid) throws TCOperationException{
        Map<String,String> criterias = new HashMap<String,String>();
        criterias.put("Cfg0AbsOptionValueThread:wso_thread.fnd0ThreadId", optionvalueid);
        ModelObject[] optionvalues = tool.queryObjectsBySavedQuery(QUERY_OPTION_VALUE, criterias);
        return optionvalues;
    }
    /**
     * 查询选项值(根据配置器关联或者是字典以及选项的ID)
     * @param optionvalueid
     * @param families
     * @return
     * @throws TCOperationException
     */
    public ModelObject[] queryOptionValue(String configurationcontext,String[] families) throws TCOperationException{
        Map<String,String> criterias = new HashMap<String,String>();
        StringBuffer families_sb =  new StringBuffer();
        criterias.put("Cfg0AbsOptionValueThread:wso_thread.Cfg0AbsAllocationThread<-cfg0TargetThread.cfg0ProductItem.item_id", configurationcontext);
        if(families != null && families.length > 0){
            for (String family : families) {
                families_sb.append(family).append(";");
            }
        }
//      System.out.println("families_sb" + families_sb.toString());
        criterias.put("cfg0OptionFamilyThread.fnd0ThreadId", families_sb.toString());
        ModelObject[] optionvalues = tool.queryObjectsBySavedQuery(QUERY_OPTION_VALUE_WITH_FAMILY, criterias);
        return optionvalues;
    }
    /**
     * 查询选项值(根据配置器关联或者是字典)
     * @param familyid
     * @throws TCOperationException
     */
    public ModelObject[] queryOptionValues(String optionvalueid,String configurationcontext) throws TCOperationException{
        Map<String,String> criterias = new HashMap<String,String>();
        criterias.put("Cfg0AbsOptionValueThread:wso_thread.fnd0ThreadId", optionvalueid);
        criterias.put("Cfg0AbsOptionValueThread:wso_thread.Cfg0AbsAllocationThread<-cfg0TargetThread.cfg0ProductItem.item_id", configurationcontext);
        ModelObject[] optionvalues = tool.queryObjectsBySavedQuery(QUERY_OPTION_VALUE, criterias);
        return optionvalues;
    }
    /**
     * 根据配置器的名称以及对象名称查询Allocation
     * @param configurationContextID
     * @param objectName
     * @return
     * @throws TCOperationException
     */
    public ModelObject[] queryAllocationValue(String configurationContextID,String objectName) throws TCOperationException{
        Map<String,String> criterias = new HashMap<String,String>();
        criterias.put("Cfg0AbsAllocationThread:wso_thread.Cfg0ConfContext:cfg0ProductItem.item_id", configurationContextID);
        criterias.put("object_name", objectName);
        ModelObject[] alloctionsvalues = tool.queryObjectsBySavedQuery(QUERY_ALLOCATION_VALUE, criterias);
        return alloctionsvalues;
    }
    /**
     * 创建family group
     * @param dictionary 字典对象
     * @param id  
     * @param desc
     * @return
     * @throws ServiceException
     */
    public  ModelObject createFamilyGroup(ModelObject dictionary,String id,String desc) throws ServiceException{
       
        CreateIn[] inputs = new CreateIn[1];
       
        CreateIn input  = new CreateIn();
        inputs[0]  = input ;
       
        Map<String,String> base_string_properties = new HashMap<String,String>();
        base_string_properties.put("object_desc", desc);
        base_string_properties.put("cfg0ObjectId", id);
       
        Map<String,BigInteger> base_int_properties = new HashMap<String,BigInteger>();
        base_int_properties.put("cfg0Sequence", BigInteger.valueOf(0));
       
        //parent dictionary
        Map<String, ModelObject[]> tagArrayProps = new HashMap<String,ModelObject[]>();
        tagArrayProps.put("cfg0ProductItems", new ModelObject[]{dictionary});
       
        //compounded properties
        Map<String, CreateInput[]> secondInput = new HashMap<String,CreateInput[]>();
        CreateInput[] secnondsinputs = new CreateInput[1];
        CreateInput secnondsinput = new CreateInput();
        secnondsinputs[0] = secnondsinput;
       
        Map<String, ModelObject> second_tagArrayProps = new HashMap<String,ModelObject>();
        second_tagArrayProps.put("cfg0ProductItem", dictionary);
       
        secnondsinput.boName = "Cfg0Allocation";
        secnondsinput.tagProps = second_tagArrayProps;
        secondInput.put("cfg0SecondaryObjects", secnondsinputs);
       
        input.data.boName = "Cfg0FamilyGroup";
        input.data.stringProps = base_string_properties;
        input.data.tagArrayProps =  tagArrayProps;
        input.data.compoundCreateInput = secondInput;
        input.data.intProps = base_int_properties;
        //create
        DataManagementService datamanagementservice = DataManagementService.getService(this.tcSession.getConnection());
        CreateResponse response = datamanagementservice.createObjects(inputs);
        ModelObject familygroup = response.output[0].objects[0];
        return familygroup;
    }
    /**
     * 将familygroup/family/optionvalue添加到dictionary对象下
     * @param dictionary
     * @param familygroup
     * @throws ServiceException
     */
    public  boolean updateObjecttoDictionary(ModelObject dictionary,ModelObject familygroup) throws ServiceException{
        DataManagementService datamanagementservice = DataManagementService.getService(this.tcSession.getConnection());
        String object_name = tool.getCommonPropertyValue(familygroup, "cfg0ObjectId");
        String uid = familygroup.getUid();
        CreateIn[] inputs = new CreateIn[1];
       
        CreateIn input  = new CreateIn();
        inputs[0]  = input ;
       
        Map<String,String> stringProps = new HashMap<String,String>();
        //stringProps.put("object_name", object_name);
       
        Map<String,Boolean> bool_properties = new HashMap<String,Boolean>();
        bool_properties.put("cfg0CascadeAssociations", false);
       
        Map<String,ModelObject> tag_properties = new HashMap<String,ModelObject>();
        tag_properties.put("cfg0ProductItem", dictionary);
        tag_properties.put("cfg0Target", familygroup);
       
        input.clientId = uid;
        input.data.boName = "Cfg0Allocation";
        input.data.stringProps = stringProps;
        input.data.boolProps = stringProps;
        input.data.tagProps = tag_properties;
        //create
       
        CreateResponse response = datamanagementservice.createObjects(inputs);
        if(response.serviceData.sizeOfPartialErrors() > 0 )
            return false;
        else
            return true;
    }
    /**
     * 将familygroup/family/optionvalue添加到configurationContext下
     * @param configurationContext
     * @param object
     * @return
     * @throws ServiceException
     */
    public  boolean updateObjecttoConfigurationContext(ModelObject configurationContext,ModelObject object) throws ServiceException{
        DataManagementService datamanagementservice = DataManagementService.getService(this.tcSession.getConnection());
        String uid = object.getUid();
        CreateIn[] inputs = new CreateIn[1];
       
        CreateIn input  = new CreateIn();
        inputs[0]  = input ;
       
        Map<String,String> stringProps = new HashMap<String,String>();
       
        Map<String,Boolean> bool_properties = new HashMap<String,Boolean>();
        bool_properties.put("cfg0CascadeAssociations", false);
       
        Map<String,ModelObject> tag_properties = new HashMap<String,ModelObject>();
        tag_properties.put("cfg0ProductItem", configurationContext);
        tag_properties.put("cfg0Target", object);
       
        input.clientId = uid;
        input.data.boName = "Cfg0Allocation";
        input.data.stringProps = stringProps;
        input.data.boolProps = stringProps;
        input.data.tagProps = tag_properties;
        //create
       
        CreateResponse response = datamanagementservice.createObjects(inputs);
        if(response.serviceData.sizeOfPartialErrors() > 0 )
            return false;
        else
            return true;
    }
    /**
     * 批量将familygroup/family/optionvalue添加到configurationContext下
     * @param configurationContext
     * @param objects
     * @return
     * @throws ServiceException
     */
    public  boolean updateObjectstoConfigurationContext(ModelObject configurationContext,ModelObject[] objects) throws ServiceException{
        DataManagementService datamanagementservice = DataManagementService.getService(this.tcSession.getConnection());
        if(objects != null && objects.length > 0){
            CreateIn[] inputs = new CreateIn[objects.length];
            for (int i = 0; i < objects.length; i++) {
                ModelObject object = objects[i];
                String uid = object.getUid();
               
                CreateIn input  = new CreateIn();
                inputs[i]  = input ;
               
                Map<String,String> stringProps = new HashMap<String,String>();
               
                Map<String,Boolean> bool_properties = new HashMap<String,Boolean>();
                bool_properties.put("cfg0CascadeAssociations", false);
               
                Map<String,ModelObject> tag_properties = new HashMap<String,ModelObject>();
                tag_properties.put("cfg0ProductItem", configurationContext);
                tag_properties.put("cfg0Target", object);
               
                input.clientId = uid;
                input.data.boName = "Cfg0Allocation";
                input.data.stringProps = stringProps;
                input.data.boolProps = stringProps;
                input.data.tagProps = tag_properties;
            }
            //create
            CreateResponse response = datamanagementservice.createObjects(inputs);
            if(response.serviceData.sizeOfPartialErrors() > 0 )
                return false;
            else
                return true;
        }
        return true;
    }
    /**
     * 将对象从配置管理器中移除
     * @param configurationContext
     * @param object_name
     * @return
     * @throws ServiceException
     * @throws TCOperationException
     */
    public  void removeObjectfromConfigurationContext(String configurationContextName,String object_name) throws ServiceException, TCOperationException{
        DataManagementService datamanagementservice = DataManagementService.getService(this.tcSession.getConnection());
        ModelObject allocationValue = null;
        if(configurationContextName != null && configurationContextName.length() >0 ){
            ModelObject[] allocationValues  = queryAllocationValue(configurationContextName, object_name);
            if(allocationValues != null && allocationValues.length > 0){
                allocationValue = allocationValues[0];
            }
        }
        if(allocationValue != null)
            datamanagementservice.deleteObjects(new ModelObject[]{allocationValue});
    }
    /**
     * 批量创建family group
     * @param dictionary
     * @param ids
     * @param desc
     * @return
     * @throws ServiceException
     */
    public  ModelObject[] createFamilyGroups(ModelObject dictionary,String[] ids,String[] desc) throws ServiceException{
        ModelObject[] createdObject = null;
        if (ids.length == desc.length ) {
            CreateIn[] inputs = new CreateIn[ids.length];
            for (int i = 0; i < ids.length; i++) {
                CreateIn input  = new CreateIn();
                inputs[i]  = input ;
               
                Map<String,String> base_string_properties = new HashMap<String,String>();
                base_string_properties.put("object_desc", desc[i]);
                base_string_properties.put("cfg0ObjectId", ids[i]);
               
                Map<String,BigInteger> base_int_properties = new HashMap<String,BigInteger>();
                base_int_properties.put("cfg0Sequence", BigInteger.valueOf(0));
               
                //parent dictionary
                Map<String, ModelObject[]> tagArrayProps = new HashMap<String,ModelObject[]>();
                tagArrayProps.put("cfg0ProductItems", new ModelObject[]{dictionary});
               
                //compounded properties
                Map<String, CreateInput[]> secondInput = new HashMap<String,CreateInput[]>();
                CreateInput[] secnondsinputs = new CreateInput[1];
                CreateInput secnondsinput = new CreateInput();
                secnondsinputs[0] = secnondsinput;
               
                Map<String, ModelObject> second_tagArrayProps = new HashMap<String,ModelObject>();
                second_tagArrayProps.put("cfg0ProductItem",dictionary);
               
                secnondsinput.boName = "Cfg0Allocation";
                secnondsinput.tagProps = second_tagArrayProps;
                secondInput.put("cfg0SecondaryObjects", secnondsinputs);
               
                input.data.boName = "Cfg0FamilyGroup";
                input.data.stringProps = base_string_properties;
                input.data.tagArrayProps =  tagArrayProps;
                input.data.compoundCreateInput = secondInput;
                input.data.intProps = base_int_properties;
            }
            //create
            DataManagementService datamanagementservice = DataManagementService.getService(this.tcSession.getConnection());
            CreateResponse response = datamanagementservice.createObjects(inputs);
            createdObject = response.output[0].objects;
        }
        return createdObject;
    }
    /**
     *创建family,并将其加到familygroup中,注意,将新增的family追加到group中,若familyGroup不存在,则不添加
     * @param dictionary 字典
     * @param familyGroup 组族
     * @param id         family ID
     * @param desc       family desc
     * @return
     * @throws ServiceException
     * @throws NotLoadedException
     */
    public  ModelObject createFamily(ModelObject dictionary,ModelObject familyGroup,String id ,String desc) throws ServiceException, NotLoadedException{

        CreateIn[] inputs = new CreateIn[1];
       
        CreateIn input  = new CreateIn();
        inputs[0]  = input ;
       
        Map<String,String> base_string_properties = new HashMap<String,String>();
        base_string_properties.put("object_desc", desc);
        base_string_properties.put("cfg0ValueDataType", "String");
        base_string_properties.put("cfg0MaximumValue", "");
        base_string_properties.put("cfg0FamilyNamespace", "Teamcenter");
        base_string_properties.put("cfg0MinimumValue", "");
        base_string_properties.put("cfg0ObjectId", id);
       
        Map<String,Boolean> base_bool_properties = new HashMap<String,Boolean>();
        base_bool_properties.put("cfg0HasFreeFormValues", false);
        base_bool_properties.put("cfg0IsMultiselect", false);
        base_bool_properties.put("cfg0IsDiscretionary", false);
       
        Map<String,BigInteger> base_int_properties = new HashMap<String,BigInteger>();
        base_int_properties.put("cfg0Sequence", BigInteger.valueOf(0));
       
        Map<String, ModelObject> base_tag_Props = new HashMap<String,ModelObject>();
        base_tag_Props.put("cfg0UOM", null);
       
        //compounded properties
        Map<String, CreateInput[]> secondInput = new HashMap<String,CreateInput[]>();
        CreateInput[] secnondsinputs = new CreateInput[1];
        CreateInput secnondsinput = new CreateInput();
        secnondsinputs[0] = secnondsinput;
       
        Map<String, ModelObject> second_tagArrayProps = new HashMap<String,ModelObject>();
        second_tagArrayProps.put("cfg0ProductItem", dictionary);
       
        secnondsinput.boName = "Cfg0Allocation";
        secnondsinput.tagProps = second_tagArrayProps;
        secondInput.put("cfg0SecondaryObjects", secnondsinputs);
       
        input.data.boName = "Cfg0LiteralValueFamily";
        input.data.stringProps = base_string_properties;
        input.data.intProps = base_int_properties;
        input.data.boolProps = base_bool_properties;
        input.data.tagProps = base_tag_Props;
        input.data.compoundCreateInput = secondInput;
       
        //create
        DataManagementService datamanagementservice = DataManagementService.getService(this.tcSession.getConnection());
        CreateResponse response = datamanagementservice.createObjects(inputs);
        ModelObject family = response.output[0].objects[0];
        addFamilytoFamilyGroup(familyGroup,new ModelObject[]{family});
        return family;
    }
    /**
     * 批量创建family,并将其加到family group 下,若family group不存在,则不做处理
     * @param dictionary 字典
     * @param familygroup 组族
     * @param ids         familyID
     * @param descs       familydesc
     * @return
     * @throws ServiceException
     * @throws NotLoadedException
     */
    public ModelObject[] createFamilies(ModelObject dictionary,ModelObject familygroup ,String[] ids ,String[] descs) throws ServiceException, NotLoadedException{
        ModelObject[] familys = null;
        if (ids.length == descs.length ) {
            CreateIn[] inputs = new CreateIn[ids.length];
            for (int i = 0; i < ids.length; i++) {
                CreateIn input  = new CreateIn();
                inputs[i]  = input ;
               
                //string properties
                Map<String,String> base_string_properties = new HashMap<String,String>();
                base_string_properties.put("object_desc", descs[i]);
                base_string_properties.put("cfg0ValueDataType", "String");
                base_string_properties.put("cfg0MaximumValue", "");
                base_string_properties.put("cfg0FamilyNamespace", "Teamcenter");
                base_string_properties.put("cfg0MinimumValue", "");
                base_string_properties.put("cfg0ObjectId", ids[i]);
               
                //bool properties
                Map<String,Boolean> base_bool_properties = new HashMap<String,Boolean>();
                base_bool_properties.put("cfg0HasFreeFormValues", false);
                base_bool_properties.put("cfg0IsMultiselect", false);
                base_bool_properties.put("cfg0IsDiscretionary", false);
               
                //int properties
                Map<String,BigInteger> base_int_properties = new HashMap<String,BigInteger>();
                base_int_properties.put("cfg0Sequence", BigInteger.valueOf(0));
               
                //tags properties
                Map<String, ModelObject> base_tag_Props = new HashMap<String,ModelObject>();
                base_tag_Props.put("cfg0UOM", null);
               
                //compounded properties
                Map<String, CreateInput[]> secondInput = new HashMap<String,CreateInput[]>();
                CreateInput[] secnondsinputs = new CreateInput[1];
                CreateInput secnondsinput = new CreateInput();
                secnondsinputs[0] = secnondsinput;
               
                Map<String, ModelObject> second_tagArrayProps = new HashMap<String,ModelObject>();
                second_tagArrayProps.put("cfg0ProductItem", dictionary);
               
                secnondsinput.boName = "Cfg0Allocation";
                secnondsinput.tagProps = second_tagArrayProps;
                secondInput.put("cfg0SecondaryObjects", secnondsinputs);
               
                input.data.boName = "Cfg0LiteralValueFamily";
                input.data.stringProps = base_string_properties;
                input.data.intProps = base_int_properties;
                input.data.boolProps = base_bool_properties;
                input.data.tagProps = base_tag_Props;
                input.data.compoundCreateInput = secondInput;
            }
            //create
            DataManagementService datamanagementservice = DataManagementService.getService(this.tcSession.getConnection());
            CreateResponse response = datamanagementservice.createObjects(inputs);
            CreateOut[] output = response.output;
            if (output != null && output.length > 0 ) {
                familys = new ModelObject[output.length];
                for (int j = 0; j < output.length; j++) {
                    familys[j] = output[j].objects[0];
                }
                addFamilytoFamilyGroup(familygroup,familys);
            }
        }
        return familys;
    }
    /**
     * 将family添加到familygroup
     * @param familyGroup
     * @param families_input
     * @throws NotLoadedException
     */
    public void addFamilytoFamilyGroup(ModelObject familyGroup,ModelObject[] families_input) throws NotLoadedException{
        DataManagementService datamanagementservice = DataManagementService.getService(this.tcSession.getConnection());
        if(familyGroup != null && families_input != null && families_input.length > 0 ){
            datamanagementservice.getProperties(new ModelObject[]{familyGroup}, new String[]{"cfg0Families"});
            ModelObject[] families = familyGroup.getPropertyObject("cfg0Families").getModelObjectArrayValue();
            String[] new_families = null;
            if(families != null && families.length > 0 ){
                new_families = new String[families.length + families_input.length];
                for (int i = 0; i < families.length; i++) {
                    new_families[i] = families[i].getUid();
                }
                for (int i = 0; i < families_input.length; i++) {
                    new_families[i+families.length] = families_input[i].getUid();
                }
            }
            else{
                new_families = new String[families_input.length];
                for (int i = 0; i < families_input.length; i++) {
                    new_families[i] = families_input[i].getUid();
                }
            }
            Map<String,VecStruct> map = new HashMap<String,VecStruct>();
            VecStruct vecStr = new VecStruct();
            vecStr.stringVec= new_families;
            map.put("cfg0Families", vecStr);
            datamanagementservice.setProperties(new ModelObject[]{familyGroup}, map);
        }
    }
    /**
     *创建选项值,默认会放到family下面
     * @param dictionary 字典
     * @param id         ID
     * @param desc       描述
     * @return
     * @throws ServiceException
     */
    public ModelObject createOptionValue(ModelObject dictionary,ModelObject family ,String id ,String desc) throws ServiceException{

        CreateIn[] inputs = new CreateIn[1];
       
        CreateIn input  = new CreateIn();
        inputs[0]  = input ;
       
        Map<String,String> base_string_properties = new HashMap<String,String>();
        base_string_properties.put("object_desc", desc);
        base_string_properties.put("cfg0ObjectId", id);
       
        Map<String,BigInteger> base_int_properties = new HashMap<String,BigInteger>();
        base_int_properties.put("cfg0Sequence", BigInteger.valueOf(0));
       
        //parent family group
        Map<String, ModelObject> base_tag_Props = new HashMap<String,ModelObject>();
        base_tag_Props.put("cfg0OptionFamily", family);
       
        //compounded properties
        Map<String, CreateInput[]> secondInput = new HashMap<String,CreateInput[]>();
        CreateInput[] secnondsinputs = new CreateInput[1];
        CreateInput secnondsinput = new CreateInput();
        secnondsinputs[0] = secnondsinput;
       
        Map<String, ModelObject> second_tagArrayProps = new HashMap<String,ModelObject>();
        second_tagArrayProps.put("cfg0ProductItem", dictionary);
       
        secnondsinput.boName = "Cfg0Allocation";
        secnondsinput.tagProps = second_tagArrayProps;
        secondInput.put("cfg0SecondaryObjects", secnondsinputs);
       
        input.data.boName = "Cfg0LiteralOptionValue";
        input.data.stringProps = base_string_properties;
        input.data.intProps = base_int_properties;
        input.data.tagProps = base_tag_Props;
        input.data.compoundCreateInput = secondInput;
       
        //create
        DataManagementService datamanagementservice = DataManagementService.getService(this.tcSession.getConnection());
        CreateResponse response = datamanagementservice.createObjects(inputs);
        ModelObject optionvalue = response.output[0].objects[0];
        logger.info("optionvalue"+optionvalue.getUid());
        return optionvalue;
    }
    /**
     *批量创建选项值,默认会放到family下面
     * @param dictionary 字典
     * @param id         ID
     * @param desc       描述
     * @return
     * @throws ServiceException
     */
    public ModelObject[] createOptionValues(ModelObject dictionary,ModelObject family ,String[] id ,String[] desc) throws ServiceException{
        ModelObject[] optionvalues = null;
        CreateIn[] inputs = null;
        if (id != null && id.length == desc.length) {
            inputs = new CreateIn[id.length];
            for (int i = 0; i < id.length; i++) {
                CreateIn input  = new CreateIn();
                inputs[i]  = input ;
               
                Map<String,String> base_string_properties = new HashMap<String,String>();
                base_string_properties.put("object_desc", desc[i]);
                base_string_properties.put("cfg0ObjectId", id[i]);
               
                Map<String,BigInteger> base_int_properties = new HashMap<String,BigInteger>();
                base_int_properties.put("cfg0Sequence", BigInteger.valueOf(0));
               
                //parent family group
                Map<String, ModelObject> base_tag_Props = new HashMap<String,ModelObject>();
                base_tag_Props.put("cfg0OptionFamily", family);
               
                //compounded properties
                Map<String, CreateInput[]> secondInput = new HashMap<String,CreateInput[]>();
                CreateInput[] secnondsinputs = new CreateInput[1];
                CreateInput secnondsinput = new CreateInput();
                secnondsinputs[0] = secnondsinput;
               
                Map<String, ModelObject> second_tagArrayProps = new HashMap<String,ModelObject>();
                second_tagArrayProps.put("cfg0ProductItem", dictionary);
               
                secnondsinput.boName = "Cfg0Allocation";
                secnondsinput.tagProps = second_tagArrayProps;
                secondInput.put("cfg0SecondaryObjects", secnondsinputs);
               
                input.data.boName = "Cfg0LiteralOptionValue";
                input.data.stringProps = base_string_properties;
                input.data.intProps = base_int_properties;
                input.data.tagProps = base_tag_Props;
                input.data.compoundCreateInput = secondInput;
            }
            //create
            DataManagementService datamanagementservice = DataManagementService.getService(this.tcSession.getConnection());
            CreateResponse response = datamanagementservice.createObjects(inputs);
            CreateOut[] output = response.output;
            if (output != null && output.length > 0 ) {
                optionvalues = new ModelObject[output.length];
                for (int i = 0; i < output.length; i++) {
                    optionvalues[i]= output[i].objects[0];
                }
            }
        }
        return optionvalues;
    }
    /**
     * 创建配置器关联
     * @param dictionary
     * @param id
     * @param name
     * @return
     * @throws ServiceException
     */
    public ModelObject createConfigurationContext(String id,String name,String desc) throws ServiceException{
        CreateIn[] inputs = new CreateIn[1];
       
        CreateIn input  = new CreateIn();
        inputs[0]  = input ;
       
        Map<String,String> base_string_properties = new HashMap<String,String>();
        base_string_properties.put("object_desc", desc);
        base_string_properties.put("item_id", id);
        base_string_properties.put("object_name", name);
       
        Map<String,Boolean> base_boolean_properties = new HashMap<String,Boolean>();
        base_boolean_properties.put("cfg0PosBiasedVariantAvail", false);
       
        //all compounded properties
        Map<String, CreateInput[]> secondInput = new HashMap<String,CreateInput[]>();
       
        //compounded properties level 1
        CreateInput[] secnondsinputs = new CreateInput[1];
        CreateInput secnondsinput = new CreateInput();
        secnondsinputs[0] = secnondsinput;
       
        Map<String, String> second_stringProps = new HashMap<String,String>();
        second_stringProps.put("item_revision_id", "");
       
        //compounded properties level 1.1
        Map<String, CreateInput[]> secondInput2 = new HashMap<String,CreateInput[]>();
        CreateInput[] secnondsinputs2 = new CreateInput[1];
        CreateInput secnondsinput2 = new CreateInput();
        secnondsinputs2[0] = secnondsinput2;
       
        Map<String, String> second_stringProps2 = new HashMap<String,String>();
        second_stringProps2.put("previous_version_id", "");
        second_stringProps2.put("item_comment", "");
        second_stringProps2.put("project_id", "");
        second_stringProps2.put("user_data_3", "");
        second_stringProps2.put("user_data_2", "");
        second_stringProps2.put("user_data_1", "");
        second_stringProps2.put("serial_number", "");
       
        secnondsinput2.boName = "Cfg0ProductItemRevisionMaster";
        secnondsinput2.stringProps = second_stringProps2;
        secondInput2.put("IMAN_master_form_rev", secnondsinputs2);
       
        secnondsinput.boName = "Cfg0ProductItemRevision";
        secnondsinput.stringProps = second_stringProps;
        secnondsinput.compoundCreateInput = secondInput2;
        secondInput.put("revision", secnondsinputs);
       
        //compounded properties level 2
        CreateInput[] thirdinputothers = new CreateInput[1];
        CreateInput thirdinputother= new CreateInput();
        thirdinputothers[0] = thirdinputother;
       
        Map<String, String> second_stringPropslevel2 = new HashMap<String,String>();
        second_stringPropslevel2.put("previous_item_id", "");
        second_stringPropslevel2.put("item_comment", "");
        second_stringPropslevel2.put("project_id", "");
        second_stringPropslevel2.put("user_data_3", "");
        second_stringPropslevel2.put("user_data_2", "");
        second_stringPropslevel2.put("user_data_1", "");
        second_stringPropslevel2.put("serial_number", "");
       
        thirdinputother.boName= "Cfg0ProductItemMaster";
        thirdinputother.stringProps = second_stringPropslevel2;
       
        secondInput.put("IMAN_master_form", thirdinputothers);
       
        input.data.boName = "Cfg0ProductItem";
        input.data.stringProps = base_string_properties;
        input.data.boolProps = base_boolean_properties;
        input.data.compoundCreateInput = secondInput;
        //create
        DataManagementService datamanagementservice = DataManagementService.getService(this.tcSession.getConnection());
        CreateResponse response = datamanagementservice.createObjects(inputs);
        ModelObject configurationContext = response.output[0].objects[0];
        return configurationContext;
    }
   
    /**
     * 创建Allocation(分配)
     * @param object_name 名称,OTB默认与粘贴对象的名称保持一致
     * @param dictionary
     * @param patested_cfg  需要将字典/配置器关联创建创建分配的组/族/选项
     * @return
     * @throws ServiceException
     */
    public ModelObject createAllocation(String object_name,ModelObject dictionary,ModelObject patested_cfg) throws ServiceException{
        CreateIn[] inputs = new CreateIn[1];
       
        CreateIn input  = new CreateIn();
        inputs[0]  = input ;
       
        Map<String,String> base_string_properties = new HashMap<String,String>();
        base_string_properties.put("object_name", object_name);
       
        Map<String,Boolean> base_bool_properties = new HashMap<String,Boolean>();
        base_bool_properties.put("cfg0CascadeAssociations", false);
       
        Map<String, ModelObject> base_tag_Props = new HashMap<String,ModelObject>();
        base_tag_Props.put("cfg0ProductItem", dictionary);
        base_tag_Props.put("cfg0Target", patested_cfg);
       
        input.data.boName = "Cfg0Allocation";
        input.data.stringProps = base_string_properties;
        input.data.boolProps = base_bool_properties;
        input.data.tagProps = base_tag_Props;
       
        //create
        DataManagementService datamanagementservice = DataManagementService.getService(this.tcSession.getConnection());
        CreateResponse response = datamanagementservice.createObjects(inputs);
        ModelObject allocation = response.output[0].objects[0];
        return allocation;
    }
    /**
     * 清除字典/配置器关联日期
     * @param fonfigurationContextModel
     */
    public void clearDate(ModelObject fonfigurationContextModel){
        //清楚日期
        DataManagementService service = DataManagementService.getService(this.tcSession.getConnection());
        ModelObject perspective = tool.getModelObjectPropertyValue(fonfigurationContextModel, "cfg0ConfigPerspective");
        Map<String,VecStruct> map = new HashMap<String,VecStruct>();
        VecStruct vecstruct = new VecStruct();
        vecstruct.stringVec = new String[]{};
        map.put("cfg0RuleSetCompileDate", vecstruct);
        service.setProperties(new ModelObject[]{perspective}, map);
    }
    /**
     * 族对象更新到字典库下(此场景适用于在族在其他字典下,但是不在当前的group下的数据)
     * @param fonfigurationContextModel
     * @throws ServiceException
     * @throws NotLoadedException
     */
    public  void upateConfiguration(ModelObject dictionary,ModelObject parent,ModelObject child) throws ServiceException, NotLoadedException{
        //先创建allocation
        String id = tool.getCommonPropertyValue(child, "cfg0ObjectId");
        createAllocation(id, dictionary, child);
        //将其添加到familygroup下
        addFamilytoFamilyGroup(parent,new ModelObject[]{child});
    }
    public void removeSVR(ModelObject configuration,ModelObject svr){
        ICTService ictservice = ICTService.getService(this.tcSession.getConnection());
        Arg[] args = new Arg[5];
        args[0]=new Arg();
        args[1]=new Arg();
        args[2]=new Arg();
        args[3]=new Arg();
        args[4]=new Arg();
       
        args[0].val="VariantRule";
        args[1].val="TYPE::VariantRule::VariantRule::WorkspaceObject";
        args[2].val =  "";
       
        ICT.Structure[] structures = new ICT.Structure[1];
        ICT.Structure structure = new ICT.Structure();
        structures[0] = structure;
        Arg[] parnet_arg = new Arg[2];
        parnet_arg[0] = new Arg();
        parnet_arg[1] = new Arg();
       
        parnet_arg[0].val = "true";
        parnet_arg[1].val = configuration.getUid();
        structure.args = parnet_arg;
        args[2].structure = structures;
       
        args[3].val =  "IMAN_reference";
       
        ICT.Array[] arrays = new ICT.Array[1];
        ICT.Array array = new ICT.Array();
        arrays[0] = array;
        Entry[] entrys = new Entry[1];
        Entry entry = new Entry();
        entrys[0] = entry;
       
        entry.val = svr.getUid();
        array.entries = entrys;
        args[4].val =  "";
        args[4].array = arrays;
        try {
            ictservice.invokeICTMethod("ICCT", "removeAndDestroyWithErrors", args);
        } catch (ServiceException e1) {
            e1.printStackTrace();
        }
    }
}
posted @   张永全-PLM顾问  阅读(116)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
点击右上角即可分享
微信分享提示