You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
273 lines
10 KiB
Java
273 lines
10 KiB
Java
|
|
import com.dassault_systemes.enovia.changeorder.factory.ChangeOrderFactory;
|
|
import com.dassault_systemes.enovia.changeorder.interfaces.IChangeOrderServices;
|
|
import com.dassault_systemes.enovia.changerequest.factory.ChangeRequestFactory;
|
|
import com.dassault_systemes.enovia.changerequest.interfaces.IAffectedItem;
|
|
import com.dassault_systemes.enovia.changerequest.interfaces.IChangeRequest;
|
|
import com.dassault_systemes.enovia.changerequest.interfaces.IChangeRequestServices;
|
|
import com.dassault_systemes.enovia.enterprisechangemgt.common.ChangeAction;
|
|
import com.dassault_systemes.enovia.enterprisechangemgtapp.common.ChangeRequest;
|
|
import com.dassault_systemes.platform.ven.jackson.databind.ObjectMapper;
|
|
import com.matrixone.apps.cpd.json.JSONObject;
|
|
import com.matrixone.apps.domain.DomainObject;
|
|
import com.matrixone.apps.domain.util.FrameworkException;
|
|
import com.matrixone.apps.domain.util.MapList;
|
|
import com.matrixone.apps.domain.util.MqlUtil;
|
|
import matrix.db.Context;
|
|
|
|
import java.util.*;
|
|
import java.util.logging.Logger;
|
|
|
|
public class CommonTools_mxJPO {
|
|
|
|
private static final Logger LOGGER = Logger.getLogger(CommonTools_mxJPO.class.getName());
|
|
|
|
public String getInfoByObjId(Context context, String[] args) {
|
|
|
|
String objId = args[0];
|
|
String selectVal = args[1];
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
List<String> list = new ArrayList<>();
|
|
|
|
if(selectVal.contains("|")){
|
|
String[] selectValInfo = selectVal.split("\\|");
|
|
for (String value : selectValInfo){
|
|
list.add(value);
|
|
stringBuilder.append(value);
|
|
stringBuilder.append(" ");
|
|
}
|
|
} else {
|
|
list.add(selectVal);
|
|
stringBuilder.append(selectVal);
|
|
}
|
|
|
|
String queryInfo = "print bus " + objId + " select " + stringBuilder + " dump |";
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
try {
|
|
String selInfo = MqlUtil.mqlCommand(context, queryInfo);
|
|
|
|
if(selInfo.isEmpty()){
|
|
return "fail";
|
|
}
|
|
|
|
if(selInfo.contains("|")){
|
|
String[] queryInfoSplit = selInfo.split("\\|");
|
|
for (int i = 0; i < queryInfoSplit.length; i++) {
|
|
jsonObject.put(list.get(i),queryInfoSplit[i]);
|
|
}
|
|
} else{
|
|
jsonObject.put(list.get(0),selInfo);
|
|
}
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
return jsonObject.toString();
|
|
}
|
|
|
|
public String getInfoByPhyId(Context context, String[] args){
|
|
|
|
String physicalId = args[0];
|
|
String selectVal = args[1];
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
List<String> list = new ArrayList<>();
|
|
|
|
if(selectVal.contains("|")){
|
|
String[] selectValInfo = selectVal.split("\\|");
|
|
for (String value : selectValInfo){
|
|
list.add(value);
|
|
stringBuilder.append(value);
|
|
stringBuilder.append(" ");
|
|
}
|
|
} else {
|
|
list.add(selectVal);
|
|
stringBuilder.append(selectVal);
|
|
}
|
|
|
|
String queryInfo = "temp query bus * * * where 'physicalid==" + physicalId + "' select " + stringBuilder + " dump |";
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
try {
|
|
String selInfo = MqlUtil.mqlCommand(context, queryInfo);
|
|
|
|
if(selInfo.isEmpty()){
|
|
return "fail";
|
|
}
|
|
|
|
if(selInfo.contains("|")){
|
|
String[] queryInfoSplit = selInfo.split("\\|");
|
|
for (int i = 3; i < queryInfoSplit.length; i++) {
|
|
jsonObject.put(list.get(i-3),queryInfoSplit[i]);
|
|
}
|
|
} else{
|
|
jsonObject.put(list.get(0),selInfo);
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
return jsonObject.toString();
|
|
}
|
|
|
|
public String getInfoByObjIdAndVersion(Context context, String[] args){
|
|
String name = args[0];
|
|
String version = args[1];
|
|
String selectList = args[2];
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
List<String> list = new ArrayList<>();
|
|
|
|
if(selectList.contains("|")){
|
|
String[] selectValInfo = selectList.split("\\|");
|
|
for (String value : selectValInfo){
|
|
list.add(value);
|
|
stringBuilder.append(value);
|
|
stringBuilder.append(" ");
|
|
}
|
|
} else {
|
|
list.add(selectList);
|
|
stringBuilder.append(selectList);
|
|
}
|
|
|
|
String queryInfo = "temp query bus * " + name + " " + version + " select " + stringBuilder + " dump |";
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
try {
|
|
String selInfo = MqlUtil.mqlCommand(context, queryInfo);
|
|
|
|
if(selInfo.isEmpty()){
|
|
return "fail";
|
|
}
|
|
|
|
if(selInfo.contains("|")){
|
|
String[] queryInfoSplit = selInfo.split("\\|");
|
|
for (int i = 3; i < queryInfoSplit.length; i++) {
|
|
jsonObject.put(list.get(i-3),queryInfoSplit[i]);
|
|
}
|
|
} else{
|
|
jsonObject.put(list.get(0),selInfo);
|
|
}
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
return jsonObject.toString();
|
|
}
|
|
|
|
public String getProposedChangeInfoByName(Context context, String[] args) throws Exception {
|
|
String Name = args[0];
|
|
LOGGER.info("Name ==> " + Name);
|
|
|
|
String getObjId = "temp query bus * " + Name + " * select id dump |";
|
|
LOGGER.info("getObjId ==> " + getObjId);
|
|
String objId = MqlUtil.mqlCommand(context, getObjId);
|
|
System.out.println(objId);
|
|
|
|
if(!objId.isEmpty()){
|
|
ChangeAction changeAction = new ChangeAction(objId.split("\\|")[3]);
|
|
MapList mapList = changeAction.getAffectedItems(context);
|
|
MapList realizedChangesList = changeAction.getRealizedChanges(context);
|
|
|
|
Map<String, Object> response = new HashMap<>();
|
|
|
|
response.put("proposedChanges", processItems(context, mapList));
|
|
response.put("realizedChanges", processItems(context, realizedChangesList));
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
return mapper.writeValueAsString(response);
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public List<Map> processItems(Context context, MapList items) throws FrameworkException {
|
|
if(items.isEmpty()) {
|
|
return null;
|
|
}
|
|
|
|
List<Map> list = new ArrayList<>();
|
|
|
|
for (int i = 0; i < items.size(); i++) {
|
|
Map<String, String> map = new HashMap<>();
|
|
Map itemMap = (Map) items.get(i);
|
|
|
|
if(!"Document".equals((String) itemMap.get("type"))) {
|
|
continue;
|
|
}
|
|
|
|
String type = (String) itemMap.get("type");
|
|
String name = (String) itemMap.get("name");
|
|
String id = (String) itemMap.get("id");
|
|
String current = (String) itemMap.get("current");
|
|
|
|
String getObjInfo = "print bus " + id + " select attribute[Title] physicalid dump |";
|
|
String objInfo = MqlUtil.mqlCommand(context, getObjInfo);
|
|
|
|
String physicalId = objInfo.split("\\|")[1];
|
|
String title = objInfo.split("\\|")[0];
|
|
|
|
map.put("title", title);
|
|
map.put("physicalid", physicalId);
|
|
map.put("name", name);
|
|
map.put("current", current);
|
|
map.put("type",type);
|
|
list.add(map);
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
public String getCRAffectInfo(Context context, String[] args) throws Exception {
|
|
String itemName = args[0];
|
|
System.out.println(123);
|
|
System.out.println(itemName);
|
|
|
|
String getItemIdInfo = "temp query bus * " + itemName + " * select id dump |";
|
|
String itemIdInfo = MqlUtil.mqlCommand(context, getItemIdInfo);
|
|
|
|
MapList mapList = new MapList();
|
|
|
|
if(!itemIdInfo.isEmpty()){
|
|
DomainObject domChange = DomainObject.newInstance(context, itemIdInfo.split("\\|")[3]);
|
|
IChangeRequestServices changeRequestFactory = ChangeRequestFactory.createChangeRequestFactory();
|
|
IChangeRequest iChangeRequest = changeRequestFactory.retrieveChangeRequestFromDatabase(context, domChange);
|
|
List<IAffectedItem> affectedItems = iChangeRequest.getAffectedItems(context);
|
|
|
|
for (int i = 0; i < affectedItems.size(); i++) {
|
|
System.out.println(affectedItems.get(i).getPhysicalId());
|
|
Map<String, String> itemMap = getCRAffectItemInfo(context, affectedItems.get(i).getPhysicalId());
|
|
|
|
if(itemMap.size() == 0){
|
|
continue;
|
|
}
|
|
mapList.add(itemMap);
|
|
}
|
|
}
|
|
|
|
System.out.println(mapList);
|
|
return mapList.toString();
|
|
}
|
|
|
|
public Map<String, String> getCRAffectItemInfo(Context context, String physicalId) throws FrameworkException {
|
|
String getItemInfo = "temp query bus * * * where ' physicalid == " + physicalId + "' select attribute[Title] type name current dump |";
|
|
System.out.println(getItemInfo);
|
|
String itemInfo = MqlUtil.mqlCommand(context, getItemInfo);
|
|
System.out.println(itemInfo);
|
|
|
|
Map<String, String> map = new HashMap();
|
|
|
|
System.out.println(itemInfo.split("\\|")[1]);
|
|
|
|
if(!itemInfo.isEmpty() && "Document".equals(itemInfo.split("\\|")[0])){
|
|
String[] itemSplit = itemInfo.split("\\|");
|
|
map.put("title", itemSplit[3]);
|
|
map.put("physicalid", physicalId);
|
|
map.put("type", itemSplit[0]);
|
|
map.put("name", itemSplit[1]);
|
|
map.put("current",itemSplit[6]);
|
|
}
|
|
|
|
return map;
|
|
}
|
|
}
|