@Test public void testSortByObfuscability() { Map<String, List<CtxModelObject>> ctxDataListRetrieved1 = DataWrapperFactory.sortByObfuscability(null); Map<String, List<CtxModelObject>> ctxDataListRetrieved2 = DataWrapperFactory.sortByObfuscability(new ArrayList<CtxModelObject>()); assertNull("Retrieved data list should be null", ctxDataListRetrieved1); assertNull("Retrieved data list should be null", ctxDataListRetrieved2); Map<String, List<CtxModelObject>> ctxDataListNameRetrieved = DataWrapperFactory.sortByObfuscability(ctxDataListName); int expectedRetrievedListSize = 1; assertNotNull("Retrieved data list should not be null", ctxDataListNameRetrieved); assertTrue(expectedRetrievedListSize+" data should be retrieved but was "+ctxDataListNameRetrieved.size(), ctxDataListNameRetrieved.size() == expectedRetrievedListSize); assertFalse("No unobfuscable data should be retrieved "+ctxDataListNameRetrieved, ctxDataListNameRetrieved.containsKey(DataWrapperFactory.NOT_OBFUSCABLE_TYPE)); assertTrue("Obfuscable data group should be used", ctxDataListNameRetrieved.containsKey(CtxAttributeTypes.NAME)); assertEquals("A correct list should be retrieved", ctxDataListName, ctxDataListNameRetrieved.get(CtxAttributeTypes.NAME)); assertEquals("A correct list should be retrieved (even copy)", ctxDataListNameCopy, ctxDataListNameRetrieved.get(CtxAttributeTypes.NAME)); Map<String, List<CtxModelObject>> ctxDataListActionRetrieved = DataWrapperFactory.sortByObfuscability(ctxDataListAction); expectedRetrievedListSize = 1; assertNotNull("Retrieved action list should not be null", ctxDataListActionRetrieved); assertTrue(expectedRetrievedListSize+" data should be retrieved but was "+ctxDataListActionRetrieved.size(), ctxDataListActionRetrieved.size() == expectedRetrievedListSize); assertTrue("No obfuscable data should be retrieved "+ctxDataListActionRetrieved, ctxDataListActionRetrieved.containsKey(DataWrapperFactory.NOT_OBFUSCABLE_TYPE)); assertEquals("A correct list should be retrieved", ctxDataListAction, ctxDataListActionRetrieved.get(DataWrapperFactory.NOT_OBFUSCABLE_TYPE)); Map<String, List<CtxModelObject>> ctxDataListLocationCoordinatesRetrieved = DataWrapperFactory.sortByObfuscability(ctxDataListLocationCoordinates); expectedRetrievedListSize = 1; assertNotNull("Retrieved data list should not be null", ctxDataListLocationCoordinatesRetrieved); assertTrue(expectedRetrievedListSize+" data should be retrieved but was "+ctxDataListLocationCoordinatesRetrieved.size(), ctxDataListLocationCoordinatesRetrieved.size() == expectedRetrievedListSize); assertFalse("No unobfuscable data should be retrieved "+ctxDataListLocationCoordinatesRetrieved, ctxDataListLocationCoordinatesRetrieved.containsKey(DataWrapperFactory.NOT_OBFUSCABLE_TYPE)); assertTrue("Obfuscable data group should be used", ctxDataListLocationCoordinatesRetrieved.containsKey(CtxAttributeTypes.LOCATION_COORDINATES)); assertEquals("A correct list should be retrieved", ctxDataListLocationCoordinates, ctxDataListLocationCoordinatesRetrieved.get(CtxAttributeTypes.LOCATION_COORDINATES)); List<CtxModelObject> ctxDataList = new ArrayList<CtxModelObject>(); ctxDataList.addAll(ctxDataListName); ctxDataList.addAll(ctxDataListAction); ctxDataList.addAll(ctxDataListLocationCoordinates); Map<String, List<CtxModelObject>> ctxDataListMixRetrieved = DataWrapperFactory.sortByObfuscability(ctxDataList); expectedRetrievedListSize = 3; assertNotNull("Retrieved data list should not be null", ctxDataListMixRetrieved); assertTrue(expectedRetrievedListSize+" data should be retrieved but was "+ctxDataListMixRetrieved.size(), ctxDataListMixRetrieved.size() == expectedRetrievedListSize); assertTrue("Unobfuscable data should be retrieved "+ctxDataListMixRetrieved, ctxDataListMixRetrieved.containsKey(DataWrapperFactory.NOT_OBFUSCABLE_TYPE)); assertEquals("Actions are unobfuscable", ctxDataListAction, ctxDataListActionRetrieved.get(DataWrapperFactory.NOT_OBFUSCABLE_TYPE)); assertTrue("Location coordinates Obfuscable data group should be retrieved", ctxDataListMixRetrieved.containsKey(CtxAttributeTypes.LOCATION_COORDINATES)); assertEquals("Locations coordinates are obfuscable", ctxDataListLocationCoordinates, ctxDataListMixRetrieved.get(CtxAttributeTypes.LOCATION_COORDINATES)); assertTrue("Location coordinates Obfuscable data group should be retrieved", ctxDataListMixRetrieved.containsKey(CtxAttributeTypes.NAME)); assertEquals("Name are obfuscable", ctxDataListName, ctxDataListMixRetrieved.get(CtxAttributeTypes.NAME)); }
public static Map<String, List<CtxModelObject>> sortByObfuscability(List<CtxModelObject> ctxDataList) { if (null == ctxDataList || ctxDataList.size() <= 0) { return null; } String notObfuscableType = "NOT_OBFUCSABLE"; DataTypeUtils dataTypeUtils = new DataTypeUtils(); ObfuscatorInfoFactory obfuscatorInfoFactory = new ObfuscatorInfoFactory(); Map<String, List<CtxModelObject>> sorted = new HashMap<String, List<CtxModelObject>>(); for(CtxModelObject data : ctxDataList) { List<CtxModelObject> dataTypeGroup = null; String dataType = data.getId().getType(); ObfuscatorInfo obfuscatorInfo = obfuscatorInfoFactory.getObfuscatorInfo(dataType); if (null != obfuscatorInfo && obfuscatorInfo.isObfuscable()) { dataTypeGroup = new ArrayList<CtxModelObject>(); dataTypeGroup.add(data); sorted.put(dataType, dataTypeGroup); continue; } String dataTypeParent = dataTypeUtils.getParent(dataType); if (null == dataTypeParent) { dataTypeParent = dataType; } obfuscatorInfo = obfuscatorInfoFactory.getObfuscatorInfo(dataTypeParent); if (null == obfuscatorInfo || !obfuscatorInfo.isObfuscable()) { dataTypeParent = notObfuscableType; } dataTypeGroup = sorted.get(dataTypeParent); if (null == dataTypeGroup) { dataTypeGroup = new ArrayList<CtxModelObject>(); } dataTypeGroup.add(data); sorted.put(dataTypeParent, dataTypeGroup); } return sorted; }
DataWrapperFactory { public static Map<String, List<CtxModelObject>> sortByObfuscability(List<CtxModelObject> ctxDataList) { if (null == ctxDataList || ctxDataList.size() <= 0) { return null; } String notObfuscableType = "NOT_OBFUCSABLE"; DataTypeUtils dataTypeUtils = new DataTypeUtils(); ObfuscatorInfoFactory obfuscatorInfoFactory = new ObfuscatorInfoFactory(); Map<String, List<CtxModelObject>> sorted = new HashMap<String, List<CtxModelObject>>(); for(CtxModelObject data : ctxDataList) { List<CtxModelObject> dataTypeGroup = null; String dataType = data.getId().getType(); ObfuscatorInfo obfuscatorInfo = obfuscatorInfoFactory.getObfuscatorInfo(dataType); if (null != obfuscatorInfo && obfuscatorInfo.isObfuscable()) { dataTypeGroup = new ArrayList<CtxModelObject>(); dataTypeGroup.add(data); sorted.put(dataType, dataTypeGroup); continue; } String dataTypeParent = dataTypeUtils.getParent(dataType); if (null == dataTypeParent) { dataTypeParent = dataType; } obfuscatorInfo = obfuscatorInfoFactory.getObfuscatorInfo(dataTypeParent); if (null == obfuscatorInfo || !obfuscatorInfo.isObfuscable()) { dataTypeParent = notObfuscableType; } dataTypeGroup = sorted.get(dataTypeParent); if (null == dataTypeGroup) { dataTypeGroup = new ArrayList<CtxModelObject>(); } dataTypeGroup.add(data); sorted.put(dataTypeParent, dataTypeGroup); } return sorted; } }
DataWrapperFactory { public static Map<String, List<CtxModelObject>> sortByObfuscability(List<CtxModelObject> ctxDataList) { if (null == ctxDataList || ctxDataList.size() <= 0) { return null; } String notObfuscableType = "NOT_OBFUCSABLE"; DataTypeUtils dataTypeUtils = new DataTypeUtils(); ObfuscatorInfoFactory obfuscatorInfoFactory = new ObfuscatorInfoFactory(); Map<String, List<CtxModelObject>> sorted = new HashMap<String, List<CtxModelObject>>(); for(CtxModelObject data : ctxDataList) { List<CtxModelObject> dataTypeGroup = null; String dataType = data.getId().getType(); ObfuscatorInfo obfuscatorInfo = obfuscatorInfoFactory.getObfuscatorInfo(dataType); if (null != obfuscatorInfo && obfuscatorInfo.isObfuscable()) { dataTypeGroup = new ArrayList<CtxModelObject>(); dataTypeGroup.add(data); sorted.put(dataType, dataTypeGroup); continue; } String dataTypeParent = dataTypeUtils.getParent(dataType); if (null == dataTypeParent) { dataTypeParent = dataType; } obfuscatorInfo = obfuscatorInfoFactory.getObfuscatorInfo(dataTypeParent); if (null == obfuscatorInfo || !obfuscatorInfo.isObfuscable()) { dataTypeParent = notObfuscableType; } dataTypeGroup = sorted.get(dataTypeParent); if (null == dataTypeGroup) { dataTypeGroup = new ArrayList<CtxModelObject>(); } dataTypeGroup.add(data); sorted.put(dataTypeParent, dataTypeGroup); } return sorted; }  }
DataWrapperFactory { public static Map<String, List<CtxModelObject>> sortByObfuscability(List<CtxModelObject> ctxDataList) { if (null == ctxDataList || ctxDataList.size() <= 0) { return null; } String notObfuscableType = "NOT_OBFUCSABLE"; DataTypeUtils dataTypeUtils = new DataTypeUtils(); ObfuscatorInfoFactory obfuscatorInfoFactory = new ObfuscatorInfoFactory(); Map<String, List<CtxModelObject>> sorted = new HashMap<String, List<CtxModelObject>>(); for(CtxModelObject data : ctxDataList) { List<CtxModelObject> dataTypeGroup = null; String dataType = data.getId().getType(); ObfuscatorInfo obfuscatorInfo = obfuscatorInfoFactory.getObfuscatorInfo(dataType); if (null != obfuscatorInfo && obfuscatorInfo.isObfuscable()) { dataTypeGroup = new ArrayList<CtxModelObject>(); dataTypeGroup.add(data); sorted.put(dataType, dataTypeGroup); continue; } String dataTypeParent = dataTypeUtils.getParent(dataType); if (null == dataTypeParent) { dataTypeParent = dataType; } obfuscatorInfo = obfuscatorInfoFactory.getObfuscatorInfo(dataTypeParent); if (null == obfuscatorInfo || !obfuscatorInfo.isObfuscable()) { dataTypeParent = notObfuscableType; } dataTypeGroup = sorted.get(dataTypeParent); if (null == dataTypeGroup) { dataTypeGroup = new ArrayList<CtxModelObject>(); } dataTypeGroup.add(data); sorted.put(dataTypeParent, dataTypeGroup); } return sorted; }  static Map<String, List<CtxModelObject>> sortByObfuscability(List<CtxModelObject> ctxDataList); static DataWrapper getDataWrapper(String obfuscableType, List<CtxModelObject> ctxDataList); static List<CtxModelObject> retrieveData(DataWrapper obfuscatedDataWrapper, List<CtxModelObject> originalCtxDataList); static DataWrapper getLocationCoordinatesWrapper(double latitude, double longitude, double accuracy); static DataWrapper getLocationCoordinatesWrapper(List<CtxModelObject> ctxDataList); static LocationCoordinates retrieveLocationCoordinates(DataWrapper dataWrapper); static List<CtxModelObject> retrieveLocationCoordinates(DataWrapper obfuscatedDataWrapper, List<CtxModelObject> originalCtxDataList); static DataWrapper getNameWrapper(String firstName, String lastName); static DataWrapper getNameWrapper(List<CtxModelObject> ctxDataList); static Name retrieveName(DataWrapper dataWrapper); static List<CtxModelObject> retrieveName(DataWrapper obfuscatedDataWrapper, List<CtxModelObject> originalCtxDataList); }
DataWrapperFactory { public static Map<String, List<CtxModelObject>> sortByObfuscability(List<CtxModelObject> ctxDataList) { if (null == ctxDataList || ctxDataList.size() <= 0) { return null; } String notObfuscableType = "NOT_OBFUCSABLE"; DataTypeUtils dataTypeUtils = new DataTypeUtils(); ObfuscatorInfoFactory obfuscatorInfoFactory = new ObfuscatorInfoFactory(); Map<String, List<CtxModelObject>> sorted = new HashMap<String, List<CtxModelObject>>(); for(CtxModelObject data : ctxDataList) { List<CtxModelObject> dataTypeGroup = null; String dataType = data.getId().getType(); ObfuscatorInfo obfuscatorInfo = obfuscatorInfoFactory.getObfuscatorInfo(dataType); if (null != obfuscatorInfo && obfuscatorInfo.isObfuscable()) { dataTypeGroup = new ArrayList<CtxModelObject>(); dataTypeGroup.add(data); sorted.put(dataType, dataTypeGroup); continue; } String dataTypeParent = dataTypeUtils.getParent(dataType); if (null == dataTypeParent) { dataTypeParent = dataType; } obfuscatorInfo = obfuscatorInfoFactory.getObfuscatorInfo(dataTypeParent); if (null == obfuscatorInfo || !obfuscatorInfo.isObfuscable()) { dataTypeParent = notObfuscableType; } dataTypeGroup = sorted.get(dataTypeParent); if (null == dataTypeGroup) { dataTypeGroup = new ArrayList<CtxModelObject>(); } dataTypeGroup.add(data); sorted.put(dataTypeParent, dataTypeGroup); } return sorted; }  static Map<String, List<CtxModelObject>> sortByObfuscability(List<CtxModelObject> ctxDataList); static DataWrapper getDataWrapper(String obfuscableType, List<CtxModelObject> ctxDataList); static List<CtxModelObject> retrieveData(DataWrapper obfuscatedDataWrapper, List<CtxModelObject> originalCtxDataList); static DataWrapper getLocationCoordinatesWrapper(double latitude, double longitude, double accuracy); static DataWrapper getLocationCoordinatesWrapper(List<CtxModelObject> ctxDataList); static LocationCoordinates retrieveLocationCoordinates(DataWrapper dataWrapper); static List<CtxModelObject> retrieveLocationCoordinates(DataWrapper obfuscatedDataWrapper, List<CtxModelObject> originalCtxDataList); static DataWrapper getNameWrapper(String firstName, String lastName); static DataWrapper getNameWrapper(List<CtxModelObject> ctxDataList); static Name retrieveName(DataWrapper dataWrapper); static List<CtxModelObject> retrieveName(DataWrapper obfuscatedDataWrapper, List<CtxModelObject> originalCtxDataList); static final String NOT_OBFUSCABLE_TYPE; }