feat: Implement scheduled task to reconcile private project data
Resolves #82 (closed)
Merge request reports
Activity
added 1 commit
- 64debc03 - feat: Add event creation if not found or no matching path
requested review from @malowe
requested review from @cguindon
99 }); 100 101 dao.add(new RDBMSQuery<>(wrapper, filters.get(PrivateProjectEvent.class)), dtos); 102 } 103 104 MultivaluedMap<String, String> includingParams = new MultivaluedMapImpl<>(); 105 106 response.get().forEach(project -> includingParams.add(GitEcaParameterNames.PROJECT_IDS.getName(), 107 Integer.toString(project.getId()))); 108 109 // Get by id since project ids never change 110 List<PrivateProjectEvent> results = dao 111 .get(new RDBMSQuery<>(wrapper, filters.get(PrivateProjectEvent.class), includingParams)); 112 113 if (results != null) { 114 List<PrivateProjectEvent> dtos = new ArrayList<>(); changed this line in version 7 of the diff
79 80 if (response.isPresent()) { 81 RequestWrapper wrapper = new FlatRequestWrapper(URI.create("https://api.eclipse.org")); 82 83 // Ad ids to be reverse searched against 84 MultivaluedMap<String, String> excludingParams = new MultivaluedMapImpl<>(); 85 86 response.get().forEach(project -> excludingParams.add(GitEcaParameterNames.NOT_IN_PROJECT_IDS.getName(), 87 Integer.toString(project.getId()))); 88 89 // Get all excluding the ids found on GL 90 List<PrivateProjectEvent> deletedResults = dao 91 .get(new RDBMSQuery<>(wrapper, filters.get(PrivateProjectEvent.class), excludingParams)); 92 93 if (deletedResults != null) { 94 List<PrivateProjectEvent> dtos = new ArrayList<>(); changed this line in version 7 of the diff
91 .get(new RDBMSQuery<>(wrapper, filters.get(PrivateProjectEvent.class), excludingParams)); 92 93 if (deletedResults != null) { 94 List<PrivateProjectEvent> dtos = new ArrayList<>(); 95 96 deletedResults.forEach(event -> { 97 event.setDeletionDate(LocalDateTime.now()); 98 dtos.add(event); 99 }); 100 101 dao.add(new RDBMSQuery<>(wrapper, filters.get(PrivateProjectEvent.class)), dtos); 102 } 103 104 MultivaluedMap<String, String> includingParams = new MultivaluedMapImpl<>(); 105 106 response.get().forEach(project -> includingParams.add(GitEcaParameterNames.PROJECT_IDS.getName(), Rather than performing
n
modifications to the map, we can inverse this and doincludingParams.put(response.get().stream().map(p -> Integer.toString(p.getId())).collect(Collectors.toList()));
to do 1 modification and make use of features of multivalue maps accepting a list as well as the individual values.changed this line in version 7 of the diff
added 1 commit
- d6cef0e1 - feat: Update iterations to use streams and maps
115 dao.add(new RDBMSQuery<>(wrapper, filters.get(PrivateProjectEvent.class)), dtos); 116 } 117 } 118 } else { 119 LOGGER.warn("Private project scan task did not run. It has been disabled through configuration."); 120 } 121 } 122 123 /** 124 * Takes a PrivatProjectEvent, copies it, updates the deletion date, and returns 125 * the copy. 126 * 127 * @param event The event to update 128 * @return a PrivateProjectEvent with an updated deletion date 129 */ 130 private PrivateProjectEvent createDtoWithDeletionDate(PrivateProjectEvent event) { 66 InstanceHandle<DefaultHibernateDao> daoHandle = Arc.container().instance(DefaultHibernateDao.class); 67 DefaultHibernateDao dao = daoHandle.get(); 68 69 InstanceHandle<FilterService> filtersHandle = Arc.container().instance(FilterService.class); 70 FilterService filters = filtersHandle.get(); 71 72 InstanceHandle<APIMiddleware> middlewareHandle = Arc.container().instance(APIMiddleware.class); 73 APIMiddleware middleware = middlewareHandle.get(); 74 75 // Fetch all private projects from GL, while paginating results 76 Optional<List<GitlabProjectResponse>> response = cache.get("all", new MultivaluedMapImpl<>(), 77 GitlabProjectResponse.class, 78 () -> middleware.getAll(p -> api.getPrivateProjects(p, apiToken, "private", 100), 79 GitlabProjectResponse.class)); 80 81 if (response.isPresent()) { rather than nest this in an if, you can make use of the
Optional.ifPresent(Consumer)
to extract the code to a new method. This reduces perceived complexity of the call and makes the code easier to maintain. With that you can probably pull the Filters and Dao getters to the new method as well as they are only used here.changed this line in version 8 of the diff
mentioned in commit ceb411b2