private void fillParentProfiles(Profile profile, List<Profile> profiles) { if (!profiles.contains(profile)) { for (String parentId : profile.getParentIds()) { Profile parent = getRequiredProfile(parentId); fillParentProfiles(parent, profiles); } profiles.add(profile); } }
private void fillParentProfiles(Profile profile, List<Profile> profiles) { if (!profiles.contains(profile)) { for (String parentId : profile.getParentIds()) { Profile parent = getRequiredProfile(parentId); fillParentProfiles(parent, profiles); } profiles.add(profile); } }
@Override public Map<String, String> getProfiles() { List<String> ids = new ArrayList<>(profileService.getProfiles()); HashMap<String, String> results = new HashMap<>(); Collections.sort(ids); for (String id : ids) { Profile profile = profileService.getProfile(id); if (profile != null) { String parents = join(" ", profile.getParentIds()); results.put(id, parents); } } return results; }
@Override public Map<String, String> getProfiles() { List<String> ids = new ArrayList<>(profileService.getProfiles()); HashMap<String, String> results = new HashMap<>(); Collections.sort(ids); for (String id : ids) { Profile profile = profileService.getProfile(id); if (profile != null) { String parents = join(" ", profile.getParentIds()); results.put(id, parents); } } return results; }
protected void createOrUpdateProfile(Profile lastProfile, Profile profile) { if (lastProfile != null) { deleteProfileFromCache(lastProfile); } try { loadCache(); for (String parentId : profile.getParentIds()) { if (!cache.containsKey(parentId)) { throw new IllegalStateException("Parent profile " + parentId + " does not exist"); } } Profiles.writeProfile(profilesDirectory, profile); if (cache != null) { cache.put(profile.getId(), profile); } } catch (IOException e) { throw new IllegalStateException("Error writing profiles", e); } }
protected void createOrUpdateProfile(Profile lastProfile, Profile profile) { if (lastProfile != null) { deleteProfileFromCache(lastProfile); } try { loadCache(); for (String parentId : profile.getParentIds()) { if (!cache.containsKey(parentId)) { throw new IllegalStateException("Parent profile " + parentId + " does not exist"); } } Profiles.writeProfile(profilesDirectory, profile); if (cache != null) { cache.put(profile.getId(), profile); } } catch (IOException e) { throw new IllegalStateException("Error writing profiles", e); } }
protected void deleteProfileFromCache(Profile lastProfile) { loadCache(); List<String> children = new ArrayList<>(); for (Profile p : cache.values()) { if (p.getParentIds().contains(lastProfile.getId())) { children.add(p.getId()); } } if (!children.isEmpty()) { throw new IllegalStateException("Profile " + lastProfile.getId() + " is a parent of " + join(", ", children)); } try { Profiles.deleteProfile(profilesDirectory, lastProfile.getId()); cache.remove(lastProfile.getId()); } catch (IOException e) { cache = null; throw new IllegalStateException("Error deleting profiles", e); } }
protected void deleteProfileFromCache(Profile lastProfile) { loadCache(); List<String> children = new ArrayList<>(); for (Profile p : cache.values()) { if (p.getParentIds().contains(lastProfile.getId())) { children.add(p.getId()); } } if (!children.isEmpty()) { throw new IllegalStateException("Profile " + lastProfile.getId() + " is a parent of " + join(", ", children)); } try { Profiles.deleteProfile(profilesDirectory, lastProfile.getId()); cache.remove(lastProfile.getId()); } catch (IOException e) { cache = null; throw new IllegalStateException("Error deleting profiles", e); } }
@Override public Object execute() throws Exception { List<String> ids = new ArrayList<>(profileService.getProfiles()); Collections.sort(ids); ShellTable table = new ShellTable(); table.column("id"); table.column("parents"); for (String id : ids) { Profile profile = profileService.getProfile(id); if (profile != null && (hidden || !profile.isHidden())) { String parents = join(" ", profile.getParentIds()); table.addRow().addContent(id, parents); } } table.print(System.out); return null; }
@Override public Object execute() throws Exception { List<String> ids = new ArrayList<>(profileService.getProfiles()); Collections.sort(ids); ShellTable table = new ShellTable(); table.column("id"); table.column("parents"); for (String id : ids) { Profile profile = profileService.getProfile(id); if (profile != null && (hidden || !profile.isHidden())) { String parents = join(" ", profile.getParentIds()); table.addRow().addContent(id, parents); } } table.print(System.out); return null; }