Skip to content

Commit

Permalink
better system for display of contributors (closes #198)
Browse files Browse the repository at this point in the history
  • Loading branch information
andponlin committed Jun 10, 2020
1 parent f8818c1 commit 206fdd3
Show file tree
Hide file tree
Showing 21 changed files with 365 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,12 @@ public interface MiscellaneousApi {

GenerateFeedUrlResult generateFeedUrl(GenerateFeedUrlRequest request) throws ObjectNotFoundException;

/**
* <p>Returns a list of all of the people who have contributed to this application server in
* some way.</p>
* @since 2020-06-10
*/

GetAllContributorsResult getAllContributors(GetAllContributorsRequest request);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.haiku.haikudepotserver.api1.model.miscellaneous;

public class GetAllContributorsRequest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.haiku.haikudepotserver.api1.model.miscellaneous;

import java.util.List;

public class GetAllContributorsResult {

private final List<Contributor> contributors;

public GetAllContributorsResult(List<Contributor> contributors) {
this.contributors = contributors;
}

public List<Contributor> getContributors() {
return contributors;
}

public static class Contributor {

public enum Type {
ENGINEERING,
LOCALIZATION
}

private final Type type;
private final String name;
private final String naturalLanguageCode;

public Contributor(Type type, String name, String naturalLanguageCode) {
this.type = type;
this.name = name;
this.naturalLanguageCode = naturalLanguageCode;
}

public Type getType() {
return type;
}

public String getName() {
return name;
}

public String getNaturalLanguageCode() {
return naturalLanguageCode;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.haiku.haikudepotserver.support;

import org.fest.assertions.Assertions;
import org.haiku.haikudepotserver.support.model.Contributor;
import org.junit.Test;

import java.util.List;

public class ContributorsServiceTest {

@Test
public void testContributors() {
// GIVEN
ContributorsService service = new ContributorsService();

// WHEN
List<Contributor> contributors = service.getConstributors();

// THEN
// check a couple of spot cases.
Assertions.assertThat(contributors).contains(
new Contributor(Contributor.Type.ENGINEERING, "Andrew Lindesay"),
new Contributor(Contributor.Type.LOCALIZATION, "Humdinger", "de")
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.haiku.haikudepotserver.feed.model.FeedService;
import org.haiku.haikudepotserver.feed.model.FeedSpecification;
import org.haiku.haikudepotserver.naturallanguage.model.NaturalLanguageService;
import org.haiku.haikudepotserver.support.ContributorsService;
import org.haiku.haikudepotserver.support.RuntimeInformationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -37,6 +38,7 @@ public class MiscellaneousApiImpl extends AbstractApiImpl implements Miscellaneo
private final ServerRuntime serverRuntime;
private final RuntimeInformationService runtimeInformationService;
private final FeedService feedService;
private final ContributorsService contributorsService;
private final MessageSource messageSource;
private final NaturalLanguageService naturalLanguageService;
private final Boolean isProduction;
Expand All @@ -48,6 +50,7 @@ public MiscellaneousApiImpl(
ServerRuntime serverRuntime,
RuntimeInformationService runtimeInformationService,
FeedService feedService,
ContributorsService contributorsService,
MessageSource messageSource,
NaturalLanguageService naturalLanguageService,
@Value("${deployment.isproduction:false}") Boolean isProduction,
Expand All @@ -56,6 +59,7 @@ public MiscellaneousApiImpl(
this.serverRuntime = Preconditions.checkNotNull(serverRuntime);
this.runtimeInformationService = Preconditions.checkNotNull(runtimeInformationService);
this.feedService = Preconditions.checkNotNull(feedService);
this.contributorsService = Preconditions.checkNotNull(contributorsService);
this.messageSource = Preconditions.checkNotNull(messageSource);
this.naturalLanguageService = Preconditions.checkNotNull(naturalLanguageService);
this.isProduction = Preconditions.checkNotNull(isProduction);
Expand Down Expand Up @@ -309,4 +313,16 @@ public GenerateFeedUrlResult generateFeedUrl(final GenerateFeedUrlRequest reques
return result;
}

@Override
public GetAllContributorsResult getAllContributors(GetAllContributorsRequest request) {
Preconditions.checkArgument(null != request);
return new GetAllContributorsResult(
contributorsService.getConstributors().stream()
.map(c -> new GetAllContributorsResult.Contributor(
GetAllContributorsResult.Contributor.Type.valueOf(c.getType().name()),
c.getName(),
c.getNaturalLanguageCode()))
.collect(Collectors.toUnmodifiableList()));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.haiku.haikudepotserver.support;

import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.StringUtils;
import org.haiku.haikudepotserver.support.model.Contributor;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;

@Service
public class ContributorsService {

public final List<Contributor> constributors;

public ContributorsService() {
this(loadContributors());
}

private ContributorsService(List<Contributor> constributors) {
this.constributors = constributors;
}

public List<Contributor> getConstributors() {
return constributors;
}

private static List<Contributor> loadContributors() {
try (InputStream inputStream = ContributorsService.class.getResourceAsStream("/contributors.properties")) {
if(null == inputStream) {
throw new IllegalStateException("unable to find the contributors file");
}
Properties properties = new Properties();
properties.load(new InputStreamReader(inputStream, Charsets.UTF_8));
return loadContributors(properties);
} catch (IOException ioe) {
throw new IllegalStateException("unable to check for presence of natural language localization", ioe);
}
}

private static List<Contributor> loadContributors(Properties properties) {
return properties.entrySet().stream()
.map(e -> createContributor(e.getKey().toString(), e.getValue().toString()))
.collect(Collectors.toUnmodifiableList());
}

private static Contributor createContributor(String propertyKey, String name) {
Preconditions.checkArgument(StringUtils.isNotBlank(propertyKey));
Preconditions.checkArgument(StringUtils.isNotBlank(name));
List<String> propertyKeyComponents = ImmutableList.copyOf(Splitter.on('.').split(propertyKey));
Contributor.Type type = Contributor.Type.valueOf(propertyKeyComponents.get(0).toUpperCase());
switch (type) {
case ENGINEERING:
return new Contributor(type, name);
case LOCALIZATION:
if (propertyKeyComponents.size() != 2) {
throw new IllegalStateException("bad property key [" + propertyKey + "]");
}
return new Contributor(type, name, propertyKeyComponents.get(1));
default:
throw new IllegalStateException("unknown type of contributor [" + type + "]");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.haiku.haikudepotserver.support.model;

import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
* <p>This record captures a person who has contributed to the project
* in some way.</p>
*/

public class Contributor {

public enum Type {
ENGINEERING,
LOCALIZATION
}

private final String name;
private final Type type;
private final String naturalLanguageCode;

public Contributor(Type type, String name) {
this(type, name, null);
}

public Contributor(Type type, String name, String naturalLanguageCode) {
Preconditions.checkArgument(null != type);
Preconditions.checkArgument(StringUtils.isNotBlank(name));
this.name = name;
this.type = type;
this.naturalLanguageCode = naturalLanguageCode;
}

public String getName() {
return name;
}

public Type getType() {
return type;
}

public String getNaturalLanguageCode() {
return naturalLanguageCode;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;

if (o == null || getClass() != o.getClass()) return false;

Contributor that = (Contributor) o;

return new EqualsBuilder()
.append(name, that.name)
.append(type, that.type)
.append(naturalLanguageCode, that.naturalLanguageCode)
.isEquals();
}

@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(name)
.append(type)
.append(naturalLanguageCode)
.toHashCode();
}

@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("type", getType())
.append("name", getName())
.append("nlcode", getNaturalLanguageCode())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
engineering=Andrew Lindesay
localization.de=Humdinger
localization.ru=Dmitriy Moroz
localization.sk=Ivan Masár
localization.ja=Murai Takashi
localization.pt=Victor Domingos
localization.tr=Emir SARI
localization.es=jjpx
localization.ca=Adolfo Jayme-Barrientos
10 changes: 10 additions & 0 deletions haikudepotserver-docs/src/docbkx/part-applicationlocalization.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,14 @@ Distributed under the terms of the MIT License.
</para>
</section>

<section>
<title>Contributors</title>

<para>
The file <code>.../haikudepotserver-core/src/main/resources/contributors.properties</code> contains a
list of the people who have contributed to the application (not the data). People who have
contributed to the localization should also include their names in this file.
</para>
</section>

</chapter>
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ breadcrumb.pkgScreenshotArchiveImport.title=Screenshot-Archiv importieren

about.info.title=Information
about.info.version=Version {0}
about.contributors.title=Beitragende
about.contributors.table.type.title=Beitrag
about.contributors.table.name.title=Namen
about.contributors.contributor.type.engineering=Programmierung
about.contributors.contributor.type.localization=Übersetzung

opensearchdescription.description=Suche nach Paketen für das Haiku Betriebssystem
opensearchdescription.shortname=Haiku Depot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ breadcrumb.pkgScreenshotArchiveImport.title=Import Screenshots

about.info.title=Information
about.info.version=Version {0}
about.contributors.title=Contributors
about.contributors.table.type.title=Contribution
about.contributors.table.name.title=Name(s)
about.contributors.contributor.type.engineering=Engineering
about.contributors.contributor.type.localization=Localization

opensearchdescription.description=Search software packages for the Haiku Operating System
opensearchdescription.shortname=Haiku Depot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,24 @@ <h1><message key="about.info.title"></message></h1>
<li><message key="about.info.version" parameters="[serverProjectVersion]"></message></li>
</ul>

<h1><message key="about.contributors.title"></message></h1>

<table class="table-general" ng-show="contributors">
<thead>
<th><message key="about.contributors.table.type.title"></message></th>
<th><message key="about.contributors.table.name.title"></message></th>
</thead>
<tbody>
<tr ng-repeat="contributor in contributors">
<td>
<message key="{{contributor.typeKey}}"></message>
<span ng-if="contributor.naturalLanguageTitle">
&mdash; {{contributor.naturalLanguageTitle}}
</span>
</td>
<td>{{contributor.name}}</td>
</tr>
</tbody>
</table>

</div>
Loading

0 comments on commit 206fdd3

Please sign in to comment.