Skip to content
Snippets Groups Projects
Commit 1b3bada7 authored by Martin Lowe's avatar Martin Lowe :flag_ca:
Browse files

Merge branch 'zacharysabourin/main/2' into 'main'

feat: Create initial WG API endpoint

See merge request !7
parents 471c0ffb 6156ded1
No related branches found
No related tags found
1 merge request!7feat: Create initial WG API endpoint
Pipeline #7043 failed
/**
* Copyright (c) 2022 Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Martin Lowe <martin.lowe@eclipse-foundation.org>
* Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipsefoundation.wg.models;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.google.auto.value.AutoValue;
/**
* JSON object for importing Working group JSON assets.
*
* @author Martin Lowe, Zachary Sabourin
*/
@AutoValue
@JsonDeserialize(builder = AutoValue_WorkingGroupMap.Builder.class)
public abstract class WorkingGroupMap {
public abstract Map<String, WorkingGroup> getWorkingGroups();
public static Builder builder() {
return new AutoValue_WorkingGroupMap.Builder();
}
@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "set")
public abstract static class Builder {
public abstract Builder setWorkingGroups(Map<String, WorkingGroup> workingGroups);
public abstract WorkingGroupMap build();
}
@AutoValue
@JsonDeserialize(builder = AutoValue_WorkingGroupMap_WorkingGroup.Builder.class)
public abstract static class WorkingGroup {
public abstract String getAlias();
public abstract String getTitle();
public abstract String getStatus();
public abstract String getLogo();
public abstract String getDescription();
public abstract String getParentOrganization();
public abstract WorkingGroupResources getResources();
public abstract List<WorkingGroupParticipationLevel> getLevels();
public static Builder builder() {
return new AutoValue_WorkingGroupMap_WorkingGroup.Builder();
}
@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "set")
public abstract static class Builder {
public abstract Builder setAlias(String alias);
public abstract Builder setTitle(String title);
public abstract Builder setStatus(String status);
public abstract Builder setLogo(String logo);
public abstract Builder setDescription(String description);
public abstract Builder setParentOrganization(String parentOrganization);
public abstract Builder setResources(WorkingGroupResources resources);
public abstract Builder setLevels(List<WorkingGroupParticipationLevel> levels);
public abstract WorkingGroup build();
}
}
@AutoValue
@JsonDeserialize(builder = AutoValue_WorkingGroupMap_WorkingGroupResources.Builder.class)
public abstract static class WorkingGroupResources {
public abstract String getCharter();
@JsonProperty("participation_agreements")
public abstract WorkingGroupParticipationAgreements getParticipationAgreements();
public abstract String getWebsite();
public abstract String getMembers();
public abstract String getSponsorship();
public abstract String getContactForm();
public static Builder builder() {
return new AutoValue_WorkingGroupMap_WorkingGroupResources.Builder();
}
@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "set")
public abstract static class Builder {
public abstract Builder setCharter(String charter);
public abstract Builder setParticipationAgreements(
WorkingGroupParticipationAgreements participationAgreements);
public abstract Builder setWebsite(String website);
public abstract Builder setMembers(String members);
public abstract Builder setSponsorship(String sponsorship);
public abstract Builder setContactForm(String contactForm);
public abstract WorkingGroupResources build();
}
}
@AutoValue
@JsonDeserialize(builder = AutoValue_WorkingGroupMap_WorkingGroupParticipationLevel.Builder.class)
public abstract static class WorkingGroupParticipationLevel {
public abstract String getRelation();
public abstract String getDescription();
public static Builder builder() {
return new AutoValue_WorkingGroupMap_WorkingGroupParticipationLevel.Builder();
}
@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "set")
public abstract static class Builder {
public abstract Builder setRelation(String relation);
public abstract Builder setDescription(String description);
public abstract WorkingGroupParticipationLevel build();
}
}
@AutoValue
@JsonDeserialize(builder = AutoValue_WorkingGroupMap_WorkingGroupParticipationAgreement.Builder.class)
public abstract static class WorkingGroupParticipationAgreement {
@JsonProperty("document_id")
public abstract String getDocumentId();
public abstract String getPdf();
public static Builder builder() {
return new AutoValue_WorkingGroupMap_WorkingGroupParticipationAgreement.Builder();
}
@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "set")
public abstract static class Builder {
public abstract Builder setDocumentId(String documentId);
public abstract Builder setPdf(String pdf);
public abstract WorkingGroupParticipationAgreement build();
}
}
@AutoValue
@JsonDeserialize(builder = AutoValue_WorkingGroupMap_WorkingGroupParticipationAgreements.Builder.class)
public abstract static class WorkingGroupParticipationAgreements {
@Nullable
public abstract WorkingGroupParticipationAgreement getIndividual();
@Nullable
public abstract WorkingGroupParticipationAgreement getOrganization();
public static Builder builder() {
return new AutoValue_WorkingGroupMap_WorkingGroupParticipationAgreements.Builder();
}
@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "set")
public abstract static class Builder {
public abstract Builder setIndividual(@Nullable WorkingGroupParticipationAgreement individual);
public abstract Builder setOrganization(@Nullable WorkingGroupParticipationAgreement organization);
public abstract WorkingGroupParticipationAgreements build();
}
}
}
package org.eclipsefoundation.wg.resources;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class GreetingResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "Hello RESTEasy";
}
}
\ No newline at end of file
/**
* Copyright (c) 2022 Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Martin Lowe <martin.lowe@eclipse-foundation.org>
* Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipsefoundation.wg.resources;
import java.util.List;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.eclipsefoundation.wg.services.WorkingGroupsService;
/**
* Retrieves working group definitions from the working groups service.
*
* @author Martin Lowe, Zachary Sabourin
*/
@Path("working_groups")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class WorkingGroupsResource {
@Inject
WorkingGroupsService wgService;
@GET
public Response getWorkingGroups(@QueryParam("status") List<String> statuses) {
// return the results as a response
return Response.ok(wgService.get(statuses)).build();
}
@GET
@Path("{name}")
public Response getWorkingGroup(@PathParam("name") String name) {
// return the results as a response
return Response.ok(wgService.getByName(name)).build();
}
}
/**
* Copyright (c) 2022 Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Martin Lowe <martin.lowe@eclipse-foundation.org>
* Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipsefoundation.wg.services;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipsefoundation.wg.models.WorkingGroupMap;
/**
* Defines a service that will return available working group data, allowing for retrieval by alias name, or the full
* set.
*
* @author Martin Lowe, Zachary Sabourin
*
*/
public interface WorkingGroupsService {
/**
* Returns a set of working groups, with an optional filter of the parent organization and project status.
*
* @param projectStatus optional, statuses to include in result set
* @return set of working groups matching optional filters if present, otherwise all available working groups
*/
public Set<WorkingGroupMap.WorkingGroup> get(List<String> projectStatus);
public WorkingGroupMap.WorkingGroup getByName(String name);
public Map<String, List<String>> getWGPADocumentIDs();
}
/**
* Copyright (c) 2022 Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Martin Lowe <martin.lowe@eclipse-foundation.org>
* Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipsefoundation.wg.services.impl;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipsefoundation.wg.models.WorkingGroupMap;
import org.eclipsefoundation.wg.models.WorkingGroupMap.WorkingGroup;
import org.eclipsefoundation.wg.models.WorkingGroupMap.WorkingGroupParticipationAgreement;
import org.eclipsefoundation.wg.services.WorkingGroupsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.quarkus.runtime.Startup;
/**
* Builds a list of working group definitions from an embedded list of working group definitions. This is an interim
* solution to accelerate this project and should be replaced with a call to the foundation API to retrieve this data.
*
* @author Martin Lowe, Zachary Sabourin
*/
@Startup
@ApplicationScoped
public class DefaultWorkingGroupsService implements WorkingGroupsService {
public static final Logger LOGGER = LoggerFactory.getLogger(DefaultWorkingGroupsService.class);
@ConfigProperty(name = "eclipse.working-groups.filepath")
String filepath;
@Inject
ObjectMapper json;
private Map<String, WorkingGroup> workingGroups;
/**
* At startup, will load the working groups and store them locally to be used throughout the servers life time. As this
* resource is embedded within the Jar, we do not need to look for changes to the resource, as that would not happen
* with a production server.
*
* @throws IOException if there is an issue loading the working groups resource from within the Jar resources.
*/
@PostConstruct
void init() throws IOException {
LOGGER.info("Starting init of working group levels static members");
try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filepath)) {
WorkingGroupMap map = json.readValue(is, WorkingGroupMap.class);
this.workingGroups = new HashMap<>(map.getWorkingGroups());
LOGGER.info("Initialized {} working group", workingGroups.size());
}
}
@Override
public Set<WorkingGroup> get(List<String> projectStatuses) {
return new HashSet<>(workingGroups
.entrySet()
.stream()
.filter(e -> filterByProjectStatuses(projectStatuses, e.getValue()))
.collect(Collectors.toMap(Entry::getKey, Entry::getValue))
.values());
}
@Override
public WorkingGroup getByName(String name) {
return workingGroups.get(name);
}
@Override
public Map<String, List<String>> getWGPADocumentIDs() {
Map<String, List<String>> wgToDocument = new HashMap<>();
workingGroups.values().stream().forEach(wg -> wgToDocument.put(wg.getAlias(), extractWGPADocumentIDs(wg)));
return wgToDocument;
}
private boolean filterByProjectStatuses(List<String> statuses, WorkingGroup wg) {
if (statuses == null || statuses.isEmpty()) {
return true;
}
return statuses.contains(wg.getStatus());
}
private List<String> extractWGPADocumentIDs(WorkingGroup wg) {
List<String> ids = new ArrayList<>();
WorkingGroupParticipationAgreement iwgpa = wg.getResources().getParticipationAgreements().getIndividual();
if (iwgpa != null) {
ids.add(iwgpa.getDocumentId());
}
WorkingGroupParticipationAgreement wgpa = wg.getResources().getParticipationAgreements().getOrganization();
if (wgpa != null) {
ids.add(wgpa.getDocumentId());
}
return ids;
}
}
fdndb-api/mp-rest/url=http://localhost:8095
fdndb-api/mp-rest/scope=javax.inject.Singleton
quarkus.oidc.enabled=false
\ No newline at end of file
quarkus.oidc.enabled=false
eclipse.working-groups.filepath=working_groups.json
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment