Skip to content

Commit 206fdd3

Browse files
committed
better system for display of contributors (closes #198)
1 parent f8818c1 commit 206fdd3

File tree

21 files changed

+365
-187
lines changed

21 files changed

+365
-187
lines changed

haikudepotserver-api1/src/main/java/org/haiku/haikudepotserver/api1/MiscellaneousApi.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,12 @@ public interface MiscellaneousApi {
8383

8484
GenerateFeedUrlResult generateFeedUrl(GenerateFeedUrlRequest request) throws ObjectNotFoundException;
8585

86+
/**
87+
* <p>Returns a list of all of the people who have contributed to this application server in
88+
* some way.</p>
89+
* @since 2020-06-10
90+
*/
91+
92+
GetAllContributorsResult getAllContributors(GetAllContributorsRequest request);
93+
8694
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.haiku.haikudepotserver.api1.model.miscellaneous;
2+
3+
public class GetAllContributorsRequest {
4+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.haiku.haikudepotserver.api1.model.miscellaneous;
2+
3+
import java.util.List;
4+
5+
public class GetAllContributorsResult {
6+
7+
private final List<Contributor> contributors;
8+
9+
public GetAllContributorsResult(List<Contributor> contributors) {
10+
this.contributors = contributors;
11+
}
12+
13+
public List<Contributor> getContributors() {
14+
return contributors;
15+
}
16+
17+
public static class Contributor {
18+
19+
public enum Type {
20+
ENGINEERING,
21+
LOCALIZATION
22+
}
23+
24+
private final Type type;
25+
private final String name;
26+
private final String naturalLanguageCode;
27+
28+
public Contributor(Type type, String name, String naturalLanguageCode) {
29+
this.type = type;
30+
this.name = name;
31+
this.naturalLanguageCode = naturalLanguageCode;
32+
}
33+
34+
public Type getType() {
35+
return type;
36+
}
37+
38+
public String getName() {
39+
return name;
40+
}
41+
42+
public String getNaturalLanguageCode() {
43+
return naturalLanguageCode;
44+
}
45+
}
46+
47+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.haiku.haikudepotserver.support;
2+
3+
import org.fest.assertions.Assertions;
4+
import org.haiku.haikudepotserver.support.model.Contributor;
5+
import org.junit.Test;
6+
7+
import java.util.List;
8+
9+
public class ContributorsServiceTest {
10+
11+
@Test
12+
public void testContributors() {
13+
// GIVEN
14+
ContributorsService service = new ContributorsService();
15+
16+
// WHEN
17+
List<Contributor> contributors = service.getConstributors();
18+
19+
// THEN
20+
// check a couple of spot cases.
21+
Assertions.assertThat(contributors).contains(
22+
new Contributor(Contributor.Type.ENGINEERING, "Andrew Lindesay"),
23+
new Contributor(Contributor.Type.LOCALIZATION, "Humdinger", "de")
24+
);
25+
}
26+
27+
}

haikudepotserver-core/src/main/java/org/haiku/haikudepotserver/api1/MiscellaneousApiImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.haiku.haikudepotserver.feed.model.FeedService;
1818
import org.haiku.haikudepotserver.feed.model.FeedSpecification;
1919
import org.haiku.haikudepotserver.naturallanguage.model.NaturalLanguageService;
20+
import org.haiku.haikudepotserver.support.ContributorsService;
2021
import org.haiku.haikudepotserver.support.RuntimeInformationService;
2122
import org.slf4j.Logger;
2223
import org.slf4j.LoggerFactory;
@@ -37,6 +38,7 @@ public class MiscellaneousApiImpl extends AbstractApiImpl implements Miscellaneo
3738
private final ServerRuntime serverRuntime;
3839
private final RuntimeInformationService runtimeInformationService;
3940
private final FeedService feedService;
41+
private final ContributorsService contributorsService;
4042
private final MessageSource messageSource;
4143
private final NaturalLanguageService naturalLanguageService;
4244
private final Boolean isProduction;
@@ -48,6 +50,7 @@ public MiscellaneousApiImpl(
4850
ServerRuntime serverRuntime,
4951
RuntimeInformationService runtimeInformationService,
5052
FeedService feedService,
53+
ContributorsService contributorsService,
5154
MessageSource messageSource,
5255
NaturalLanguageService naturalLanguageService,
5356
@Value("${deployment.isproduction:false}") Boolean isProduction,
@@ -56,6 +59,7 @@ public MiscellaneousApiImpl(
5659
this.serverRuntime = Preconditions.checkNotNull(serverRuntime);
5760
this.runtimeInformationService = Preconditions.checkNotNull(runtimeInformationService);
5861
this.feedService = Preconditions.checkNotNull(feedService);
62+
this.contributorsService = Preconditions.checkNotNull(contributorsService);
5963
this.messageSource = Preconditions.checkNotNull(messageSource);
6064
this.naturalLanguageService = Preconditions.checkNotNull(naturalLanguageService);
6165
this.isProduction = Preconditions.checkNotNull(isProduction);
@@ -309,4 +313,16 @@ public GenerateFeedUrlResult generateFeedUrl(final GenerateFeedUrlRequest reques
309313
return result;
310314
}
311315

316+
@Override
317+
public GetAllContributorsResult getAllContributors(GetAllContributorsRequest request) {
318+
Preconditions.checkArgument(null != request);
319+
return new GetAllContributorsResult(
320+
contributorsService.getConstributors().stream()
321+
.map(c -> new GetAllContributorsResult.Contributor(
322+
GetAllContributorsResult.Contributor.Type.valueOf(c.getType().name()),
323+
c.getName(),
324+
c.getNaturalLanguageCode()))
325+
.collect(Collectors.toUnmodifiableList()));
326+
}
327+
312328
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package org.haiku.haikudepotserver.support;
2+
3+
import com.google.common.base.Charsets;
4+
import com.google.common.base.Preconditions;
5+
import com.google.common.base.Splitter;
6+
import com.google.common.collect.ImmutableList;
7+
import org.apache.commons.lang.StringUtils;
8+
import org.haiku.haikudepotserver.support.model.Contributor;
9+
import org.springframework.stereotype.Service;
10+
11+
import java.io.IOException;
12+
import java.io.InputStream;
13+
import java.io.InputStreamReader;
14+
import java.util.List;
15+
import java.util.Properties;
16+
import java.util.stream.Collectors;
17+
18+
@Service
19+
public class ContributorsService {
20+
21+
public final List<Contributor> constributors;
22+
23+
public ContributorsService() {
24+
this(loadContributors());
25+
}
26+
27+
private ContributorsService(List<Contributor> constributors) {
28+
this.constributors = constributors;
29+
}
30+
31+
public List<Contributor> getConstributors() {
32+
return constributors;
33+
}
34+
35+
private static List<Contributor> loadContributors() {
36+
try (InputStream inputStream = ContributorsService.class.getResourceAsStream("/contributors.properties")) {
37+
if(null == inputStream) {
38+
throw new IllegalStateException("unable to find the contributors file");
39+
}
40+
Properties properties = new Properties();
41+
properties.load(new InputStreamReader(inputStream, Charsets.UTF_8));
42+
return loadContributors(properties);
43+
} catch (IOException ioe) {
44+
throw new IllegalStateException("unable to check for presence of natural language localization", ioe);
45+
}
46+
}
47+
48+
private static List<Contributor> loadContributors(Properties properties) {
49+
return properties.entrySet().stream()
50+
.map(e -> createContributor(e.getKey().toString(), e.getValue().toString()))
51+
.collect(Collectors.toUnmodifiableList());
52+
}
53+
54+
private static Contributor createContributor(String propertyKey, String name) {
55+
Preconditions.checkArgument(StringUtils.isNotBlank(propertyKey));
56+
Preconditions.checkArgument(StringUtils.isNotBlank(name));
57+
List<String> propertyKeyComponents = ImmutableList.copyOf(Splitter.on('.').split(propertyKey));
58+
Contributor.Type type = Contributor.Type.valueOf(propertyKeyComponents.get(0).toUpperCase());
59+
switch (type) {
60+
case ENGINEERING:
61+
return new Contributor(type, name);
62+
case LOCALIZATION:
63+
if (propertyKeyComponents.size() != 2) {
64+
throw new IllegalStateException("bad property key [" + propertyKey + "]");
65+
}
66+
return new Contributor(type, name, propertyKeyComponents.get(1));
67+
default:
68+
throw new IllegalStateException("unknown type of contributor [" + type + "]");
69+
}
70+
}
71+
72+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package org.haiku.haikudepotserver.support.model;
2+
3+
import com.google.common.base.Preconditions;
4+
import org.apache.commons.lang3.StringUtils;
5+
import org.apache.commons.lang3.builder.EqualsBuilder;
6+
import org.apache.commons.lang3.builder.HashCodeBuilder;
7+
import org.apache.commons.lang3.builder.ToStringBuilder;
8+
import org.apache.commons.lang3.builder.ToStringStyle;
9+
10+
/**
11+
* <p>This record captures a person who has contributed to the project
12+
* in some way.</p>
13+
*/
14+
15+
public class Contributor {
16+
17+
public enum Type {
18+
ENGINEERING,
19+
LOCALIZATION
20+
}
21+
22+
private final String name;
23+
private final Type type;
24+
private final String naturalLanguageCode;
25+
26+
public Contributor(Type type, String name) {
27+
this(type, name, null);
28+
}
29+
30+
public Contributor(Type type, String name, String naturalLanguageCode) {
31+
Preconditions.checkArgument(null != type);
32+
Preconditions.checkArgument(StringUtils.isNotBlank(name));
33+
this.name = name;
34+
this.type = type;
35+
this.naturalLanguageCode = naturalLanguageCode;
36+
}
37+
38+
public String getName() {
39+
return name;
40+
}
41+
42+
public Type getType() {
43+
return type;
44+
}
45+
46+
public String getNaturalLanguageCode() {
47+
return naturalLanguageCode;
48+
}
49+
50+
@Override
51+
public boolean equals(Object o) {
52+
if (this == o) return true;
53+
54+
if (o == null || getClass() != o.getClass()) return false;
55+
56+
Contributor that = (Contributor) o;
57+
58+
return new EqualsBuilder()
59+
.append(name, that.name)
60+
.append(type, that.type)
61+
.append(naturalLanguageCode, that.naturalLanguageCode)
62+
.isEquals();
63+
}
64+
65+
@Override
66+
public int hashCode() {
67+
return new HashCodeBuilder(17, 37)
68+
.append(name)
69+
.append(type)
70+
.append(naturalLanguageCode)
71+
.toHashCode();
72+
}
73+
74+
@Override
75+
public String toString() {
76+
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
77+
.append("type", getType())
78+
.append("name", getName())
79+
.append("nlcode", getNaturalLanguageCode())
80+
.build();
81+
}
82+
83+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
engineering=Andrew Lindesay
2+
localization.de=Humdinger
3+
localization.ru=Dmitriy Moroz
4+
localization.sk=Ivan Masár
5+
localization.ja=Murai Takashi
6+
localization.pt=Victor Domingos
7+
localization.tr=Emir SARI
8+
localization.es=jjpx
9+
localization.ca=Adolfo Jayme-Barrientos

haikudepotserver-docs/src/docbkx/part-applicationlocalization.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,14 @@ Distributed under the terms of the MIT License.
126126
</para>
127127
</section>
128128

129+
<section>
130+
<title>Contributors</title>
131+
132+
<para>
133+
The file <code>.../haikudepotserver-core/src/main/resources/contributors.properties</code> contains a
134+
list of the people who have contributed to the application (not the data). People who have
135+
contributed to the localization should also include their names in this file.
136+
</para>
137+
</section>
138+
129139
</chapter>

haikudepotserver-webapp/src/main/resources/webmessages_de.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ breadcrumb.pkgScreenshotArchiveImport.title=Screenshot-Archiv importieren
7979

8080
about.info.title=Information
8181
about.info.version=Version {0}
82+
about.contributors.title=Beitragende
83+
about.contributors.table.type.title=Beitrag
84+
about.contributors.table.name.title=Namen
85+
about.contributors.contributor.type.engineering=Programmierung
86+
about.contributors.contributor.type.localization=Übersetzung
8287

8388
opensearchdescription.description=Suche nach Paketen für das Haiku Betriebssystem
8489
opensearchdescription.shortname=Haiku Depot

0 commit comments

Comments
 (0)