-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better system for display of contributors (closes #198)
- Loading branch information
Showing
21 changed files
with
365 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...n/java/org/haiku/haikudepotserver/api1/model/miscellaneous/GetAllContributorsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.haiku.haikudepotserver.api1.model.miscellaneous; | ||
|
||
public class GetAllContributorsRequest { | ||
} |
47 changes: 47 additions & 0 deletions
47
...in/java/org/haiku/haikudepotserver/api1/model/miscellaneous/GetAllContributorsResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...r-core-test/src/test/java/org/haiku/haikudepotserver/support/ContributorsServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...epotserver-core/src/main/java/org/haiku/haikudepotserver/support/ContributorsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + "]"); | ||
} | ||
} | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
...udepotserver-core/src/main/java/org/haiku/haikudepotserver/support/model/Contributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
haikudepotserver-core/src/main/resources/contributors.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.