@Override public ServiceResults getEntityCommand( ServiceContext context, List<EntityRef> refs, String command ) throws Exception { if ( "hello".equalsIgnoreCase( command ) ) { ServiceResults results = genericServiceResults().withData( hashMap( "say", "Hello!" ) ); return results; } return super.getEntityCommand( context, refs, command ); }
/** * Uses {@link JsonUtils#mapToFormattedJsonString(Object)} against the object if the duration is greater than {@link * #timerLogThreshold}. When using the varargs form, the number of elements must be even such that key,value,key, * value mapping via {@link MapUtils#map(Object...)} can collect all the elements. * <p/> * Conversion to a map this way let's us lazy create the map if and only if the triggering threshold is true or we * are in debug mode. */ public void maybeLogPayload( long duration, Object... objects ) { if ( duration > timerLogThreshold || logger.isInfoEnabled() ) { String message; if ( objects.length > 1 ) { message = formatMessage( duration, MapUtils.map( objects ) ); } else { message = formatMessage( duration, objects ); } logger.info( message ); } }
public static Map<String, ?> putPath( String path, Object value ) { return putPath( null, path, value ); }
@SuppressWarnings("unchecked") public static Map<String, List<?>> toMapList( Map<String, ?> m ) { Map<String, List<Object>> mapList = new LinkedHashMap<String, List<Object>>(); for ( Entry<String, ?> e : m.entrySet() ) { if ( e.getValue() instanceof List ) { addListToMapList( mapList, e.getKey(), ( List<Object> ) e.getValue() ); } else { addMapList( mapList, e.getKey(), e.getValue() ); } } return cast( mapList ); }
public void mapCollector( String entityType, String containerType, String collectionName, CollectionInfo collection ) { MapUtils.addMapMapSet( entityContainerCollections, true, entityType, containerType, collection ); if ( !collection.getPropertiesIndexed().isEmpty() ) { MapUtils.addMapMapSet( entityContainerCollectionsIndexingProperties, true, entityType, containerType, collection ); for ( String propertyName : collection.getPropertiesIndexed() ) { MapUtils.addMapMapMapSet( entityPropertyContainerCollectionsIndexingProperty, true, entityType, propertyName, containerType, collection ); } } if ( !collection.getDictionariesIndexed().isEmpty() ) { MapUtils.addMapMapSet( entityContainerCollectionsIndexingDictionaries, true, entityType, containerType, collection ); for ( String dictionaryName : collection.getDictionariesIndexed() ) { MapUtils.addMapMapMapSet( entityDictionaryContainerCollectionsIndexingDictionary, true, entityType, dictionaryName, containerType, collection ); } } if ( collection.isIndexingDynamicDictionaries() ) { MapUtils.addMapMapSet( entityContainerCollectionsIndexingDynamicDictionaries, true, entityType, containerType, collection ); } }
public static <A, B> void addMapSet( Map<A, Set<B>> map, A a, B b ) { addMapSet( map, false, a, b ); }
public static <A, B, C> void addMapMapSet( Map<A, Map<B, Set<C>>> map, A a, B b, C c ) { addMapMapSet( map, false, a, b, c ); }
public Map<String, String> getPropertiesMap() { if ( properties != null ) { return asMap( properties ); } return null; }
@SuppressWarnings("unchecked") public static <A, B, C> void addMapMapSet( Map<A, Map<B, Set<C>>> map, boolean ignoreCase, A a, B b, C c ) { Map<B, Set<C>> mapB = map.get( a ); if ( mapB == null ) { if ( ignoreCase && ( b instanceof String ) ) { mapB = ( Map<B, Set<C>> ) new TreeMap<String, Set<C>>( String.CASE_INSENSITIVE_ORDER ); } else { mapB = new LinkedHashMap<B, Set<C>>(); } map.put( a, mapB ); } addMapSet( mapB, ignoreCase, b, c ); }
@SuppressWarnings("unchecked") public static <A, B, C, D> void addMapMapMapSet( Map<A, Map<B, Map<C, Set<D>>>> map, boolean ignoreCase, A a, B b, C c, D d ) { Map<B, Map<C, Set<D>>> mapB = map.get( a ); if ( mapB == null ) { if ( ignoreCase && ( b instanceof String ) ) { mapB = ( Map<B, Map<C, Set<D>>> ) new TreeMap<String, Map<C, Set<D>>>( String.CASE_INSENSITIVE_ORDER ); } else { mapB = new LinkedHashMap<B, Map<C, Set<D>>>(); } map.put( a, mapB ); } addMapMapSet( mapB, ignoreCase, b, c, d ); }
public static Properties filter( Properties properties, String prefix, boolean removePrefix ) { Properties filteredProperties = new Properties(); for ( Entry<String, String> entry : asMap( properties ).entrySet() ) { if ( entry.getKey().startsWith( prefix ) ) { if ( removePrefix ) { filteredProperties.put( entry.getKey().substring( prefix.length() ), entry.getValue() ); } else { filteredProperties.put( entry.getKey(), entry.getValue() ); } } } return filteredProperties; }
public void sendAdminUserInvitedEmail( UserInfo user, OrganizationInfo organization ) throws Exception { sendAdminUserEmail( user, "User Invited To Organization", emailMsg( hashMap( "organization_name", organization.getName() ), PROPERTIES_EMAIL_ADMIN_INVITED ) ); }
@SuppressWarnings("unchecked") public static Map<String, ?> putPath( Map<String, ?> map, String path, Object value ) { if ( map == null ) { map = new HashMap<String, Object>(); } int i = path.indexOf( '.' ); if ( i < 0 ) { ( ( Map<String, Object> ) map ).put( path, value ); return map; } String segment = path.substring( 0, i ).trim(); if ( isNotBlank( segment ) ) { Object o = map.get( segment ); if ( ( o != null ) && ( !( o instanceof Map ) ) ) { return map; } Map<String, Object> subMap = ( Map<String, Object> ) o; if ( subMap == null ) { subMap = new HashMap<String, Object>(); ( ( Map<String, Object> ) map ).put( segment, subMap ); } String subPath = path.substring( i + 1 ); if ( isNotBlank( subPath ) ) { putPath( subMap, subPath, value ); } } return map; }
@SuppressWarnings("unchecked") @Test public void testUnroll() { Map<String, Object> json = new LinkedHashMap<String, Object>(); json.put( "name", "edanuff" ); json.put( "cat", "fishbone" ); json.put( "city", "San Francisco" ); json.put( "car", "bmw" ); json.put( "stuff", Arrays.asList( 1, 2, 3, 4, 5 ) ); json.put( "phones", Arrays.asList( MapUtils.map( "a", "b" ), MapUtils.map( "a", "c" ), MapUtils.map( "b", MapUtils.map( "d", "e", "d", "f" ) ) ) ); dumpJson( "obj", json ); dumpJson( "propname", Arrays.asList( 1, 2, 3, 4, 5 ) ); dumpJson( "propname", 125 ); System.out.println( JsonUtils.mapToJsonString( json ) ); Object result = JsonUtils.select( json, "phones" ); System.out.println( JsonUtils.mapToJsonString( result ) ); result = JsonUtils.select( json, "phones.a" ); System.out.println( JsonUtils.mapToJsonString( result ) ); }
private Map<String, Set<CollectionInfo>> addDynamicApplicationCollectionAsContainer( Map<String, Set<CollectionInfo>> containers, String entityType ) { Map<String, Set<CollectionInfo>> copy = new TreeMap<String, Set<CollectionInfo>>( String.CASE_INSENSITIVE_ORDER ); if ( containers != null ) { copy.putAll( containers ); } containers = copy; if ( !containers.containsKey( Application.ENTITY_TYPE ) ) { MapUtils.addMapSet( containers, true, Application.ENTITY_TYPE, getCollection( Application.ENTITY_TYPE, defaultCollectionName( entityType ) ) ); } return containers; }
@Override public Map<String, Map<UUID, Set<String>>> getOwners() throws Exception { // TODO: do we need to restrict this to edges prefixed with owns? //Map<EntityRef, Set<String>> containerEntities = getContainers(-1, "owns", null); Map<EntityRef, Set<String>> containerEntities = getContainers(); Map<String, Map<UUID, Set<String>>> owners = new LinkedHashMap<String, Map<UUID, Set<String>>>(); for ( EntityRef owner : containerEntities.keySet() ) { Set<String> collections = containerEntities.get( owner ); for ( String collection : collections ) { MapUtils.addMapMapSet( owners, owner.getType(), owner.getUuid(), collection ); } } return owners; }
public void sendAdminUserConfirmedAwaitingActivationEmail( UserInfo user ) throws Exception { sendAdminUserEmail(user, "User Account Confirmed", emailMsg( hashMap("confirmed_email",user.getEmail() ), PROPERTIES_EMAIL_ADMIN_CONFIRMED_AWAITING_ACTIVATION ) ); }
addMapSet( entityRefSetMap, eref, name ); } ).toBlocking().last();
public void sendOrganizationActivatedEmail( OrganizationInfo organization ) throws Exception { sendOrganizationEmail( organization, "Organization Account Activated: " + organization.getName(), emailMsg( hashMap( "organization_name", organization.getName() ), PROPERTIES_EMAIL_ORGANIZATION_ACTIVATED ) ); }