use of org.codice.alliance.nsili.common.UID.Product in project alliance by codice.
the class ResultDAGConverter method convertResult.
public static DAG convertResult(Result result, ORB orb, POA poa, List<String> resultAttributes, Map<String, List<String>> mandatoryAttributes) throws DagParsingException {
Metacard metacard = result.getMetacard();
DAG dag = new DAG();
DirectedAcyclicGraph<Node, Edge> graph = new DirectedAcyclicGraph<>(Edge.class);
ProductImpl productImpl = new ProductImpl();
String id = result.getMetacard().getId();
if (!CorbaUtils.isIdActive(poa, id.getBytes(Charset.forName(ENCODING)))) {
try {
poa.activate_object_with_id(id.getBytes(Charset.forName(ENCODING)), productImpl);
} catch (ServantAlreadyActive | ObjectAlreadyActive | WrongPolicy e) {
LOGGER.debug("Convert DAG : Unable to activate product impl object ({}): {}", result.getMetacard().getId(), e.getLocalizedMessage());
}
}
org.omg.CORBA.Object obj = poa.create_reference_with_id(id.getBytes(Charset.forName(ENCODING)), ProductHelper.id());
Product product = ProductHelper.narrow(obj);
Node productNode = createRootNode(orb);
String attributeName = NsiliConstants.NSIL_PRODUCT;
Any productAny = orb.create_any();
ProductHelper.insert(productAny, product);
productNode.value = productAny;
graph.addVertex(productNode);
List<String> addedAttributes = new ArrayList<>();
addedAttributes.addAll(addCardNodeWithAttributes(graph, productNode, metacard, orb, attributeName + ":", resultAttributes));
addedAttributes.addAll(addFileNodeWithAttributes(graph, productNode, metacard, orb, attributeName + ":", resultAttributes));
addedAttributes.addAll(addSecurityNodeWithAttributes(graph, productNode, metacard, orb, attributeName + ":", resultAttributes));
addedAttributes.addAll(addMetadataSecurityNodeWithAttributes(graph, productNode, metacard, orb, attributeName + ":", resultAttributes));
addedAttributes.addAll(addParts(graph, productNode, metacard, orb, attributeName + ":", resultAttributes));
if (metacard.getThumbnail() != null && metacard.getThumbnail().length > 0) {
addedAttributes.addAll(addThumbnailRelatedFile(graph, productNode, metacard, orb, attributeName + ":", resultAttributes));
}
if (mandatoryAttributes != null && !mandatoryAttributes.isEmpty()) {
final ThreadLocal<Boolean> dataIsValid = new ThreadLocal<>();
dataIsValid.set(true);
Map<String, List<String>> addedAttrMap = getAttrMap(addedAttributes);
addedAttrMap.entrySet().forEach(entry -> dataIsValid.set(dataIsValid.get() && processEntry(entry.getKey(), mandatoryAttributes.get(entry.getKey()), entry.getValue())));
if (!dataIsValid.get()) {
throw new DagParsingException("One or more mandatory attributes is missing on outgoing data");
}
}
graph.addVertex(productNode);
NsiliCommonUtils.setUCOEdgeIds(graph);
NsiliCommonUtils.setUCOEdges(productNode, graph);
dag.edges = NsiliCommonUtils.getEdgeArrayFromGraph(graph);
dag.nodes = NsiliCommonUtils.getNodeArrayFromGraph(graph);
return dag;
}
use of org.codice.alliance.nsili.common.UID.Product in project alliance by codice.
the class Client method evaluateResult.
private void evaluateResult(SampleNsiliClient sampleNsiliClient, DAG[] results, int index) throws Exception {
LOGGER.info("\t RESULT : {} of {} ", (index + 1), results.length);
String obsoleteName = NsiliCardStatus.OBSOLETE.name();
if (getAttributeFromDag(results[index], NsiliConstants.STATUS).equalsIgnoreCase(obsoleteName)) {
LOGGER.info("Record is {}. Not testing result", obsoleteName);
} else {
sampleNsiliClient.printDagAttributes(results[index]);
if (SHOULD_DOWNLOAD_PRODUCT) {
sampleNsiliClient.downloadProductFromDAG(results[index]);
}
// ProductMgr
LOGGER.info("-----------------------");
try {
sampleNsiliClient.testProductMgr(results[index]);
} catch (Exception e) {
LOGGER.info("Unable to test ProductMgr: {}", NsilCorbaExceptionUtil.getExceptionDetails(e));
}
LOGGER.info("-----------------------");
// OrderMgr
PackageElement[] packageElements = sampleNsiliClient.order(results[index]);
// ProductMgr
if (SHOULD_PROCESS_PKG_ELEMENTS) {
for (PackageElement packageElement : packageElements) {
Product product = packageElement.prod;
sampleNsiliClient.getParameters(product);
sampleNsiliClient.getRelatedFileTypes(product);
sampleNsiliClient.getRelatedFiles(product);
}
}
}
}
use of org.codice.alliance.nsili.common.UID.Product in project alliance by codice.
the class SampleNsiliClient method testProductMgr.
public void testProductMgr(DAG dag) throws Exception {
if (productMgr != null) {
LOGGER.info("--------------------------");
LOGGER.info("Getting ProductMgr Use Modes");
final String[] useModes = productMgr.get_use_modes();
for (String useMode : useModes) {
LOGGER.info(TAB_LOG_MSG, useMode);
}
final short numPriorities = productMgr.get_number_of_priorities();
LOGGER.info("Product Mgr num of priorities: {}", numPriorities);
final Product product = getProductFromDag(dag);
LOGGER.info("Product is available tests ");
final boolean avail = productMgr.is_available(product, useModes[0]);
LOGGER.info("\t {} : {}", useModes[0], avail);
final String productID = getProductIdFromDag(dag);
LOGGER.info("Getting CORE, ALL, and ORDER parameters for : {}", productID);
getParameters(product);
LOGGER.info("Getting related file types for : {}", productID);
getRelatedFileTypes(product);
LOGGER.info("Getting thumbnail for : {}", productID);
getRelatedFiles(product);
} else {
LOGGER.warn("ProductMgr is not initialized, unable to test");
}
}
use of org.codice.alliance.nsili.common.UID.Product in project alliance by codice.
the class AccessManagerImplTest method testIsAvailableWithBadURL.
@Test
public void testIsAvailableWithBadURL() throws Exception {
MetacardImpl testMetacard = new MetacardImpl();
testMetacard.setId(testMetacardId);
testMetacard.setTitle("JUnit Test Card");
testMetacard.setAttribute(new AttributeImpl(Metacard.RESOURCE_DOWNLOAD_URL, "http://localhost:20999/not/present"));
Result testResult = new ResultImpl(testMetacard);
List<Result> results = new ArrayList<>();
results.add(testResult);
QueryResponse testResponse = new QueryResponseImpl(null, results, results.size());
when(mockCatalogFramework.query(any(QueryRequest.class))).thenReturn(testResponse);
DAG dag = ResultDAGConverter.convertResult(testResult, orb, rootPOA, new ArrayList<>(), new HashMap<>());
Product product = ProductHelper.extract(dag.nodes[0].value);
boolean avail = accessManager.is_available(product, null);
assertThat(avail, is(false));
avail = accessManager.is_available(null, null);
assertThat(avail, is(false));
}
use of org.codice.alliance.nsili.common.UID.Product in project alliance by codice.
the class AccessManagerImplTest method testIsAvailableNoURL.
@Test
public void testIsAvailableNoURL() throws Exception {
MetacardImpl testMetacard = new MetacardImpl();
testMetacard.setId(testMetacardId);
testMetacard.setTitle("JUnit Test Card");
Result testResult = new ResultImpl(testMetacard);
DAG dag = ResultDAGConverter.convertResult(testResult, orb, rootPOA, new ArrayList<>(), new HashMap<>());
Product product = ProductHelper.extract(dag.nodes[0].value);
boolean avail = accessManager.is_available(product, null);
assertThat(avail, is(false));
avail = accessManager.is_available(null, null);
assertThat(avail, is(false));
}
Aggregations