/**
* 批量设置IBA属性
* @param doc 文档对象
* @param ibas iba集合,key为属性名,Value为属性值
* @throws WTException
*/
public static void setIBAValue(WTDocument doc, Map<String, Object> ibas) throws WTException{
if (ibas != null && !ibas.isEmpty()) {
LWCNormalizedObject lwcObject = new LWCNormalizedObject(doc, null, SessionHelper.getLocale(),new UpdateOperationIdentifier());
Iterator<String> keyIt = ibas.keySet().iterator();
String key = null;
lwcObject.load(ibas.keySet());
while (keyIt.hasNext()) {
key = keyIt.next();
lwcObject.set(key, ibas.get(key));
}
lwcObject.apply();
}
}
/**
* 根据类型、IBA属性查找文档
* @param docType 文档类型
* @param ibaName iba属性名
* @param ibaValue iba属性值
* @return 文档对象
* @throws WTException
*/
public static List<WTDocument> getDocumentsByIba(String docType,String ibaName,String ibaValue) throws WTException {
List<WTDocument> docList = new ArrayList<WTDocument>();
Hashtable<Object, Object> iba = new Hashtable<>();
iba.put(ibaName, ibaValue);
QuerySpec qs = new QuerySpec(WTDocument.class);
qs.setAdvancedQueryEnabled(true);
int indexDoc = qs.addClassList(WTDocument.class, true);
int indexDocMaster = qs.addClassList(WTDocumentMaster.class, false);
int indextype = qs.addClassList(WTTypeDefinition.class, false);
int indextypeMaster = qs.addClassList(WTTypeDefinitionMaster.class,false);
SearchCondition docLatest = new SearchCondition(WTDocument.class,WTDocument.LATEST_ITERATION, SearchCondition.IS_TRUE, true);
qs.appendWhere(docLatest, new int[] { indexDoc });
qs.appendAnd();
SearchCondition scdoc = new SearchCondition(WTDocument.class,"masterReference.key.id", WTDocumentMaster.class,"thePersistInfo.theObjectIdentifier.id");
qs.appendWhere(scdoc, new int[] { indexDoc, indexDocMaster });
qs.appendAnd();
SearchCondition scLink = new SearchCondition(WTDocument.class,"typeDefinitionReference.key.id", WTTypeDefinition.class,"thePersistInfo.theObjectIdentifier.id");
qs.appendWhere(scLink, new int[] { indexDoc, indextype });
qs.appendAnd();
SearchCondition scepm = new SearchCondition(WTTypeDefinitionMaster.class,"thePersistInfo.theObjectIdentifier.id",WTTypeDefinition.class, "masterReference.key.id");
qs.appendWhere(scepm, new int[] { indextypeMaster, indextype });
qs.appendAnd();
SearchCondition scMast = new SearchCondition(WTTypeDefinitionMaster.class,WTTypeDefinitionMaster.INT_HID, SearchCondition.EQUAL, docType);
qs.appendWhere(scMast, new int[] { indextypeMaster });
qs.appendAnd();
SearchCondition scMastDelete = new SearchCondition(WTTypeDefinitionMaster.class,WTTypeDefinitionMaster.DELETED_ID, SearchCondition.IS_NULL, true);
qs.appendWhere(scMastDelete, new int[] { indextypeMaster });
addIBASearchCondition(WTDocument.class, qs, iba);
QueryResult result = PersistenceHelper.manager.find(qs);
while(result.hasMoreElements()) {
Object obj = result.nextElement();
if (obj instanceof Object[]) {
docList.add((WTDocument)((Object[]) obj)[0]);
} else {
docList.add((WTDocument)obj);
}
}
return docList;
}
/**
* 添加iba属性搜索条件
* @param ibaHolderClass 查询目标类型
* @param qs 查询语句
* @param htIBAS iba属性集合 key位属性名,value位属性值
* @throws QueryException
*/
public static void addIBASearchCondition(Class ibaHolderClass, QuerySpec qs, Hashtable htIBAS) throws QueryException {
Enumeration eIBA = htIBAS.keys();
while (eIBA.hasMoreElements()) {
int ibaStringDefinitionIndex = qs.appendClassList(StringDefinition.class, false);
int iIndex_StringValue = qs.appendClassList(StringValue.class, false);
String strIBA_Name = (String) eIBA.nextElement();
String strIBA_Value = (String) htIBAS.get(strIBA_Name);
logger.debug("IBA_Name:" + strIBA_Name + "====>IBA_Value:" + strIBA_Value);
ClassAttribute caValue = new ClassAttribute(StringValue.class, StringValue.VALUE);
SQLFunction upperFunction = new SQLFunction("UPPER", caValue);
String strOP = SearchCondition.EQUAL;
if (strIBA_Value != null && (strIBA_Value.indexOf('*') != -1 || strIBA_Value.indexOf('%') != -1)) {
strOP = SearchCondition.LIKE;
}
SearchCondition scStringValueValue = new SearchCondition(upperFunction, strOP, new ConstantExpression(new String(strIBA_Value).toUpperCase()));
SearchCondition scStringDefinitionName = new SearchCondition(StringDefinition.class, StringDefinition.NAME, SearchCondition.EQUAL, strIBA_Name);
SearchCondition scJoinStringValueStringDefinition = new SearchCondition(StringValue.class, "definitionReference.key.id", StringDefinition.class, WTAttributeNameIfc.ID_NAME);
SearchCondition scStringValueDoc = new SearchCondition(StringValue.class, "theIBAHolderReference.key.id", ibaHolderClass, WTAttributeNameIfc.ID_NAME);
if (qs.getConditionCount() > 0) {
qs.appendAnd();
}
qs.appendWhere(scStringValueValue, new int[] { iIndex_StringValue });
qs.appendAnd();
int iIBAHolderIndex = qs.getFromClause().getPosition(ibaHolderClass);
qs.appendWhere(scStringValueDoc, new int[] { iIndex_StringValue, iIBAHolderIndex });
qs.appendAnd();
qs.appendWhere(scJoinStringValueStringDefinition, new int[] { iIndex_StringValue, ibaStringDefinitionIndex });
qs.appendAnd();
qs.appendWhere(scStringDefinitionName, new int[] { ibaStringDefinitionIndex });
}
}
/**
* 设置String类型iba属性
* @param obj 目标对象
* @param ibaName iba属性名称
* @param newValue iba属性值
* @throws WTException
*/
public static void setIBAStringValue(WTObject obj, String ibaName, String newValue) throws WTException {
String ibaClass = "wt.iba.definition.StringDefinition";
if (obj instanceof IBAHolder) {
IBAHolder ibaHolder = (IBAHolder) obj;
DefaultAttributeContainer defaultattributecontainer = getContainer(ibaHolder);
if (defaultattributecontainer == null) {
defaultattributecontainer = new DefaultAttributeContainer();
ibaHolder.setAttributeContainer(defaultattributecontainer);
}
StringValueDefaultView abstractvaluedefaultview = (StringValueDefaultView) getIBAValueView(
defaultattributecontainer, ibaName, ibaClass);
if (abstractvaluedefaultview != null) {
try {
abstractvaluedefaultview.setValue(newValue);
} catch (WTPropertyVetoException e) {
logger.error(e.getLocalizedMessage(), e);
throw new WTException(e);
}
defaultattributecontainer.updateAttributeValue(abstractvaluedefaultview);
} else {
AttributeDefDefaultView attributedefdefaultview = getAttributeDefinition(ibaName, false);
StringValueDefaultView abstractvaluedefaultview1 = new StringValueDefaultView(
(StringDefView) attributedefdefaultview, newValue);
defaultattributecontainer.addAttributeValue(abstractvaluedefaultview1);
}
ibaHolder.setAttributeContainer(defaultattributecontainer);
StandardIBAValueService.theIBAValueDBService.updateAttributeContainer(ibaHolder, null, null, null);
try {
ibaHolder = IBAValueHelper.service.refreshAttributeContainer(ibaHolder, "CSM", null, null);
} catch (RemoteException e) {
logger.error(e.getLocalizedMessage(), e);
throw new WTException(e);
}
}
}
/**
* 获取IBA属性值
* @param holder 目标对象
* @param ibaName iba属性名称
* @return iba属性值
* @throws WTException
*/
public static String getIBAValue(IBAHolder holder, String ibaName) throws WTException {
AttributeDefDefaultView addv = null;
try {
addv = IBADefinitionHelper.service.getAttributeDefDefaultViewByPath(ibaName);
} catch (RemoteException e) {
logger.error(e.getLocalizedMessage(), e);
throw new WTException(e);
}
if (addv == null) {
throw new WTException("undefined iba name :" + ibaName);
}
long ibaDefId = addv.getObjectID().getId();
QuerySpec qs = new QuerySpec(StringValue.class);
qs.appendWhere(new SearchCondition(StringValue.class,
AbstractValue.IBAHOLDER_REFERENCE + "." + ObjectReference.KEY + "." + ObjectIdentifier.ID,
SearchCondition.EQUAL,
PersistenceHelper.getObjectIdentifier((Persistable) holder).getId()), new int[] { 0 });
qs.appendAnd();
qs.appendWhere(new SearchCondition(StringValue.class, StringValue.DEFINITION_REFERENCE + "."
+ ObjectReference.KEY
+ "." + ObjectIdentifier.ID, SearchCondition.EQUAL, ibaDefId), new int[] { 0 });
QueryResult qr = PersistenceHelper.manager.find((StatementSpec) qs);
StringValue sv = null;
if (qr.hasMoreElements()) {
sv = (StringValue) qr.nextElement();
}
return sv == null ? null : sv.getValue();
}
04-27
1230
09-23
1660
06-30
1454
10-12