Windchill 11.0 查询分类特征的默认值

通过内部值查询分类对象

public LWCStructEnumAttTemplate getClassificationByInternalName(String internalName) throws WTException {
        QuerySpec spec = new QuerySpec(LWCStructEnumAttTemplate.class);
        spec.appendWhere(new SearchCondition(LWCStructEnumAttTemplate.class, LWCStructEnumAttTemplate.NAME,
                SearchCondition.EQUAL, internalName), new int[]{0});
        spec.appendAnd();
        //排除已删除数据
        spec.appendWhere(new SearchCondition(LWCStructEnumAttTemplate.class, LWCStructEnumAttTemplate.DELETED_ID, true), new int[] {0});
        QueryResult qur = PersistenceHelper.manager.find(spec);
        while (qur.hasMoreElements()) {
            Object obj = qur.nextElement();
            if (obj instanceof LWCStructEnumAttTemplate) {
                return (LWCStructEnumAttTemplate) obj;
            }
        }
        return null;
    }

查询分类属性的默认值

private Serializable getLWCStructEnumAttTemplateDefualtValue(LWCStructEnumAttTemplate lwcStructEnumAttTemplate, String attrName) throws Exception {
        QuerySpec spec = new QuerySpec();
        int defaultValueIndex = spec.appendClassList(LWCAttributeDefaultValue.class, true);
        int lwcIbaDef = spec.appendClassList(LWCIBAAttDefinition.class, false);
        int strDefIndex = spec.appendClassList(StringDefinition.class, false);
        spec.appendWhere(new SearchCondition(StringDefinition.class,StringDefinition.NAME,SearchCondition.EQUAL,attrName),new int[]{strDefIndex});
        spec.appendAnd();
        spec.appendWhere(new SearchCondition(StringDefinition.class,"thePersistInfo.theObjectIdentifier.id",
                LWCIBAAttDefinition.class,"ibaReference.key.id"
                ), new int[]{strDefIndex, lwcIbaDef});
        spec.appendAnd();
        spec.appendWhere(new SearchCondition(LWCIBAAttDefinition.class,"thePersistInfo.theObjectIdentifier.id",
                LWCAttributeDefaultValue.class,"attributeReference.key.id"
        ), new int[]{lwcIbaDef,defaultValueIndex});
        spec.appendAnd();
        spec.appendWhere(new SearchCondition(LWCAttributeDefaultValue.class,"contextReference.key.id",SearchCondition.EQUAL,
                lwcStructEnumAttTemplate.getPersistInfo().getObjectIdentifier().getId()),new int[]{defaultValueIndex});
        QueryResult qr = PersistenceHelper.manager.find(spec);
        if (qr.hasMoreElements()) {
            Object[] obj = (Object[]) qr.nextElement();
            LWCAttributeDefaultValue  defaultValue= (LWCAttributeDefaultValue) obj[0];
            Serializable defaultValueValue = defaultValue.getValue();
            if(defaultValueValue!=null){
                return defaultValueValue.toString();
            }
        }
        return "";
    }

最后使用的代码

private String getClassificationAttrDefualtValue(String classificationInternalName,  String attrName) throws Exception {
        if (StringUtils.isBlank(classificationInternalName)) {
            return "";
        }
        LWCStructEnumAttTemplate lwcStructEnumAttTemplate = getClassificationByInternalName(classificationInternalName);
        if (lwcStructEnumAttTemplate == null) {
            return "";
        }
        Serializable serializable = getLWCStructEnumAttTemplateDefualtValue(lwcStructEnumAttTemplate, attrName);;
        return serializable.toString();
    }

你可能感兴趣的:(java,windchill,java)