DefaultMetadataExportService implements MetadataExportService { @Override @SuppressWarnings( "unchecked" ) public MetadataExportParams getParamsFromMap( Map<String, List<String>> parameters ) { MetadataExportParams params = new MetadataExportParams(); Map<Class<? extends IdentifiableObject>, Map<String, List<String>>> map = new HashMap<>(); params.setDefaults( getEnumWithDefault( Defaults.class, parameters, "defaults", Defaults.INCLUDE ) ); params.setInclusionStrategy( getEnumWithDefault( InclusionStrategy.Include.class, parameters, "inclusionStrategy", InclusionStrategy.Include.NON_NULL ) ); if ( parameters.containsKey( "fields" ) ) { params.setDefaultFields( parameters.get( "fields" ) ); parameters.remove( "fields" ); } if ( parameters.containsKey( "filter" ) ) { params.setDefaultFilter( parameters.get( "filter" ) ); parameters.remove( "filter" ); } if ( parameters.containsKey( "order" ) ) { params.setDefaultOrder( parameters.get( "order" ) ); parameters.remove( "order" ); } if ( parameters.containsKey( "skipSharing" ) ) { params.setSkipSharing( Boolean.parseBoolean( parameters.get( "skipSharing" ).get( 0 ) ) ); parameters.remove( "skipSharing" ); } for ( String parameterKey : parameters.keySet() ) { String[] parameter = parameterKey.split( ":" ); Schema schema = schemaService.getSchemaByPluralName( parameter[0] ); if ( schema == null || !schema.isIdentifiableObject() ) { continue; } Class<? extends IdentifiableObject> klass = (Class<? extends IdentifiableObject>) schema.getKlass(); if ( isSelectedClass( parameters.get( parameterKey ) ) || (parameter.length > 1 && ("fields".equalsIgnoreCase( parameter[1] ) || "filter".equalsIgnoreCase( parameter[1] ) || "order".equalsIgnoreCase( parameter[1] ))) ) { if ( !map.containsKey( klass ) ) map.put( klass, new HashMap<>() ); } else { continue; } if ( parameter.length > 1 ) { if ( "fields".equalsIgnoreCase( parameter[1] ) ) { if ( !map.get( klass ).containsKey( "fields" ) ) map.get( klass ).put( "fields", new ArrayList<>() ); map.get( klass ).get( "fields" ).addAll( parameters.get( parameterKey ) ); } if ( "filter".equalsIgnoreCase( parameter[1] ) ) { if ( !map.get( klass ).containsKey( "filter" ) ) map.get( klass ).put( "filter", new ArrayList<>() ); map.get( klass ).get( "filter" ).addAll( parameters.get( parameterKey ) ); } if ( "order".equalsIgnoreCase( parameter[1] ) ) { if ( !map.get( klass ).containsKey( "order" ) ) map.get( klass ).put( "order", new ArrayList<>() ); map.get( klass ).get( "order" ).addAll( parameters.get( parameterKey ) ); } } } map.keySet().forEach( params::addClass ); for ( Class<? extends IdentifiableObject> klass : map.keySet() ) { Map<String, List<String>> classMap = map.get( klass ); Schema schema = schemaService.getDynamicSchema( klass ); if ( classMap.containsKey( "fields" ) ) params.addFields( klass, classMap.get( "fields" ) ); if ( classMap.containsKey( "filter" ) && classMap.containsKey( "order" ) ) { OrderParams orderParams = new OrderParams( Sets.newHashSet( classMap.get( "order" ) ) ); Query query = queryService.getQueryFromUrl( klass, classMap.get( "filter" ), orderParams.getOrders( schema ) ); query.setDefaultOrder(); params.addQuery( query ); } else if ( classMap.containsKey( "filter" ) ) { Query query = queryService.getQueryFromUrl( klass, classMap.get( "filter" ), new ArrayList<>() ); query.setDefaultOrder(); params.addQuery( query ); } else if ( classMap.containsKey( "order" ) ) { OrderParams orderParams = new OrderParams(); orderParams.setOrder( Sets.newHashSet( classMap.get( "order" ) ) ); Query query = queryService.getQueryFromUrl( klass, new ArrayList<>(), orderParams.getOrders( schema ) ); query.setDefaultOrder(); params.addQuery( query ); } } return params; }  @Override @SuppressWarnings( "unchecked" ) Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> getMetadata( MetadataExportParams params ); @Override RootNode getMetadataAsNode( MetadataExportParams params ); @Override void validate( MetadataExportParams params ); @Override @SuppressWarnings( "unchecked" ) MetadataExportParams getParamsFromMap( Map<String, List<String>> parameters ); @Override SetMap<Class<? extends IdentifiableObject>, IdentifiableObject> getMetadataWithDependencies( IdentifiableObject object ); @Override RootNode getMetadataWithDependenciesAsNode( IdentifiableObject object, @Nonnull MetadataExportParams params );  }
@Test public void getParamsFromMapIncludedSecondary() { Mockito.when( schemaService.getSchemaByPluralName( Mockito.eq( "jobConfigurations" ) ) ) .thenReturn( new Schema( JobConfiguration.class, "jobConfiguration", "jobConfigurations" ) ); Mockito.when( schemaService.getSchemaByPluralName( Mockito.eq( "options" ) ) ) .thenReturn( new Schema( Option.class, "option", "options" ) ); final Map<String, List<String>> params = new HashMap<>(); params.put( "jobConfigurations", Collections.singletonList( "true" ) ); params.put( "options", Collections.singletonList( "true" ) ); MetadataExportParams exportParams = service.getParamsFromMap( params ); Assert.assertTrue( exportParams.getClasses().contains( JobConfiguration.class ) ); Assert.assertTrue( exportParams.getClasses().contains( Option.class ) ); }
@Test public void getParamsFromMapNotIncludedSecondary() { Mockito.when( schemaService.getSchemaByPluralName( Mockito.eq( "jobConfigurations" ) ) ) .thenReturn( new Schema( JobConfiguration.class, "jobConfiguration", "jobConfigurations" ) ); Mockito.when( schemaService.getSchemaByPluralName( Mockito.eq( "options" ) ) ) .thenReturn( new Schema( Option.class, "option", "options" ) ); final Map<String, List<String>> params = new HashMap<>(); params.put( "jobConfigurations", Arrays.asList( "true", "false" ) ); params.put( "options", Collections.singletonList( "true" ) ); MetadataExportParams exportParams = service.getParamsFromMap( params ); Assert.assertFalse( exportParams.getClasses().contains( JobConfiguration.class ) ); Assert.assertTrue( exportParams.getClasses().contains( Option.class ) ); }
@Test public void getParamsFromMapNoSecondary() { Mockito.when( schemaService.getSchemaByPluralName( Mockito.eq( "options" ) ) ) .thenReturn( new Schema( Option.class, "option", "options" ) ); final Map<String, List<String>> params = new HashMap<>(); params.put( "options", Collections.singletonList( "true" ) ); MetadataExportParams exportParams = service.getParamsFromMap( params ); Assert.assertFalse( exportParams.getClasses().contains( JobConfiguration.class ) ); Assert.assertTrue( exportParams.getClasses().contains( Option.class ) ); }