1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| public void testSearch(HashSet itemList) { long startTime = System.currentTimeMillis(); FieldSearchDimension productIDSearchDimension = new FieldSearchDimension(repSchema.getFieldId(TABLEID_PRODUCTS, "ProductID"));
Set idList = itemList; Iterator<String> it = idList.iterator(); int lastPageIndex = idList.size() % PAGE_SIZE == 0 ? idList.size() / PAGE_SIZE : idList.size() / PAGE_SIZE + 1; ResultDefinition rd = new ResultDefinition(tableId); FieldId[] fieldIds = new FieldId[]{fieldProductID, fieldIdOriDB, fieldIdSentToEnovia, fieldIdSendToPCIR, fieldIdP20Relevant}; rd.setSelectFields(fieldIds); Search search = new Search(tableId); RetrieveLimitedRecordsCommand rlrc = new RetrieveLimitedRecordsCommand(connection); int pageIdx = 0; rlrc.setPageSize(PAGE_SIZE); rlrc.setResultDefinition(rd); int updateConuntNEPEPLM = 0; int updateConuntPCIR = 0; int updateConuntP20 = 0; int updateConuntSentToEnovia = 0; for (int pageIndex = 0; pageIndex < lastPageIndex; pageIndex++) { int count = 0; Set<String> searchSet = new HashSet<String>(idList.size());
for (count = 0; count < PAGE_SIZE && idList.size() > 0; count++) { String s = it.next(); searchSet.add(s); SearchConstraint scProductId = new TextSearchConstraint(s, TextSearchConstraint.EQUALS); search.addSearchItem(productIDSearchDimension, scProductId); it.remove(); }
rlrc.setSearch(search); rlrc.setSession(session); rlrc.setPageIndex(0); try { rlrc.execute(); } catch (CommandException e) { e.printStackTrace(); logger.error(e.getMessage()); return; } Record[] records = rlrc.getRecords().getRecords(); for (Record record : records) { try { if (Boolean.valueOf(String.valueOf(record.getFieldValue(fieldIdSendToPCIR)))) { updateConuntPCIR++; record.setFieldValue(fieldIdSendToPCIR, new BooleanValue(Boolean.valueOf(VALUE_Send_To_PCIR))); } if (Boolean.valueOf(String.valueOf(record.getFieldValue(fieldIdP20Relevant)))) { updateConuntP20++; record.setFieldValue(fieldIdP20Relevant, new BooleanValue(Boolean.valueOf(VALUE_P20_Relevant))); } record.setFieldValue(fieldIdSentToEnovia, new BooleanValue(Boolean.valueOf(VALUE_Sent_To_Enovia))); if (Boolean.valueOf(String.valueOf(record.getFieldValue(fieldIdSentToEnovia)))) { updateConuntSentToEnovia++; } record.setFieldValue(fieldIdOriDB, new LookupValue(recordOriDBNEP.getId())); if (!"NEP".equalsIgnoreCase(String.valueOf(record.getLookupDisplayValue(fieldIdOriDB)))) { updateConuntNEPEPLM++; }
logger.debug("item" + record.getFieldValue(fieldProductID) + ",pcir:" + String.valueOf(record.getFieldValue(fieldIdSendToPCIR)) + ",oridb:" + String.valueOf(record.getLookupDisplayValue(fieldIdOriDB))); logger.debug("sent to enovia:" + String.valueOf(record.getFieldValue(fieldIdSentToEnovia))); logger.debug(",p20:" + String.valueOf(record.getFieldValue(fieldIdP20Relevant)));
} catch (Exception e) { e.printStackTrace(); logger.error("MDM Value Type Exception::" + e.getMessage()); } } ModifyRecordsCommand modifyRecordsCommand = new ModifyRecordsCommand(connection); modifyRecordsCommand.setRecords(records); modifyRecordsCommand.setSession(session); modifyRecordsCommand.setTableId(tableId); try { modifyRecordsCommand.execute(); } catch (CommandException e) { e.printStackTrace(); logger.error(e.getMessage()); }
int[] crFailed = modifyRecordsCommand.getResult().getFailedRecords();
if (crFailed != null && crFailed.length > 0) { logger.info("modifyRecords: No. of records failed:" + crFailed.length); for (int i = 0; i < crFailed.length; i++) { int j = crFailed[i]; logger.info("modifyRecords: failed messages:" + modifyRecordsCommand.getResult().getFailedRecordMessage(j)); } }
int crSuccess[] = modifyRecordsCommand.getResult().getSucceededRecords(); if (crSuccess != null && crSuccess.length > 0) logger.info("modifyRecords: No. of records succeeded:" + crSuccess.length);
} DestroySessionCommand destroySessionCommand = new DestroySessionCommand(connection); destroySessionCommand.setSession(session);
try { destroySessionCommand.execute(); } catch (CommandException e) { e.printStackTrace(); logger.error(e.getMessage()); return; } long endTime = System.currentTimeMillis();
logger.info("update nep item number::" + updateConuntNEPEPLM); logger.info("update sent to enovia item number::" + updateConuntSentToEnovia); logger.info("update P20 Relevant item number::" + updateConuntP20); logger.info("update attribute send to pcir to N,,Total number:" + updateConuntPCIR); logger.info("update attribute values done in alpim, total time::" + (endTime - startTime) / 1000 + "s"); }
|