private static void populateFirstClassEntities(Map<String, String> eventDescription){ CallContext context = CallContext.current(); Map<Object, Object> contextMap = context.getContextParameters(); for(Map.Entry<Object, Object> entry : contextMap.entrySet()){ try{ Class<?> clz = (Class<?>)entry.getKey(); if(clz != null && Identity.class.isAssignableFrom(clz)){ String uuid = getEntityUuid(clz, entry.getValue()); eventDescription.put(ReflectUtil.getEntityName(clz), uuid); } } catch (Exception e){ s_logger.trace("Caught exception while populating first class entities for event bus, moving on"); } } }
/** * display flag is used to control the display of the resource only to the end user. It doesnt affect Root Admin. * @return display flag */ public boolean isDisplay(){ CallContext context = CallContext.current(); Map<Object, Object> contextMap = context.getContextParameters(); boolean isDisplay = true; // Iterate over all the first class entities in context and check their display property. for(Map.Entry<Object, Object> entry : contextMap.entrySet()){ try{ Object key = entry.getKey(); Class clz = Class.forName((String)key); if(Displayable.class.isAssignableFrom(clz)){ final Object objVO = getEntityVO(clz, entry.getValue()); isDisplay = ((Displayable) objVO).isDisplay(); } // If the flag is false break immediately if(!isDisplay) break; } catch (Exception e){ s_logger.trace("Caught exception while checking first class entities for display property, continuing on", e); } } context.setEventDisplayEnabled(isDisplay); return isDisplay; }
@Test public void testGetContextParameter() { CallContext currentContext = CallContext.current(); Assert.assertEquals("There is nothing in the context. It should return null", null, currentContext.getContextParameter("key")); Assert.assertTrue("There is nothing in the context. The map should be empty", currentContext.getContextParameters().isEmpty()); UUID objectUUID = UUID.randomUUID(); UUID stringUUID = UUID.randomUUID(); //Case1: when an entry with the object class is present currentContext.putContextParameter(User.class, objectUUID); Assert.assertEquals("it should return objectUUID: " + objectUUID, objectUUID, currentContext.getContextParameter(User.class)); Assert.assertEquals("current context map should have exactly one entry", 1, currentContext.getContextParameters().size()); //Case2: when an entry with the object class name as String is present currentContext.putContextParameter(Account.class.toString(), stringUUID); //object is put with key as Account.class.toString but get with key as Account.class Assert.assertEquals("it should return stringUUID: " + stringUUID, stringUUID, currentContext.getContextParameter(Account.class)); Assert.assertEquals("current context map should have exactly two entries", 2, currentContext.getContextParameters().size()); //Case3: when an entry with both object class and object class name as String is present //put an entry of account class object in the context currentContext.putContextParameter(Account.class, objectUUID); //since both object and string a present in the current context, it should return object value Assert.assertEquals("it should return objectUUID: " + objectUUID, objectUUID, currentContext.getContextParameter(Account.class)); Assert.assertEquals("current context map should have exactly three entries", 3, currentContext.getContextParameters().size()); }
params.put("ctxDetails", ApiGsonHelper.getBuilder().create().toJson(ctx.getContextParameters()));