Skip to content

Commit

Permalink
Merge pull request #288 from zanata/ZNTA-1915-language-users
Browse files Browse the repository at this point in the history
Znta 1915 language users
  • Loading branch information
Alex Eng committed Apr 26, 2017
2 parents 6e8e1a3 + d645765 commit 5923992
Show file tree
Hide file tree
Showing 26 changed files with 706 additions and 388 deletions.
Expand Up @@ -18,13 +18,11 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.rest.search.dto;
package org.zanata.rest.dto;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.zanata.common.LocaleId;
import org.zanata.model.HLocale;
import org.zanata.rest.dto.LocaleDetails;

/**
* @author Carlos Munoz
Expand All @@ -40,16 +38,7 @@ public LanguageTeamSearchResult() {
this.setType(SearchResultType.LanguageTeam);
}

public LanguageTeamSearchResult(HLocale locale) {
this.setType(SearchResultType.LanguageTeam);
this.setId(locale.getLocaleId().getId());
this.localeDetails = new LocaleDetails(locale.getLocaleId(),
locale.retrieveDisplayName(), null, locale.retrieveNativeName(),
locale.isActive(), locale.isEnabledByDefault(),
locale.getPluralForms());
this.memberCount = locale.getMembers().size();
}

@JsonProperty("localeDetails")
public LocaleDetails getLocaleDetails() {
return this.localeDetails;
}
Expand All @@ -58,6 +47,7 @@ public void setLocaleDetails(final LocaleDetails localeDetails) {
this.localeDetails = localeDetails;
}

@JsonProperty("memberCount")
public long getMemberCount() {
return this.memberCount;
}
Expand Down
@@ -0,0 +1,93 @@
/*
* Copyright 2014, Red Hat, Inc. and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.zanata.rest.dto;

import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import java.io.Serializable;

@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class LocaleMember implements Serializable {

private final String username;
private final Boolean isCoordinator;
private final Boolean isReviewer;
private final Boolean isTranslator;


public LocaleMember(String username, Boolean isCoordinator,
Boolean isReviewer, Boolean isTranslator) {
this.username = username;
this.isCoordinator = isCoordinator;
this.isReviewer = isReviewer;
this.isTranslator = isTranslator;
}

@JsonProperty("username")
public String getUsername() {
return username;
}

@JsonProperty("isCoordinator")
public Boolean getCoordinator() {
return isCoordinator;
}

@JsonProperty("isReviewer")
public Boolean getReviewer() {
return isReviewer;
}

@JsonProperty("isTranslator")
public Boolean getTranslator() {
return isTranslator;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

LocaleMember that = (LocaleMember) o;

if (username != null ? !username.equals(that.username) :
that.username != null) return false;
if (isCoordinator != null ? !isCoordinator.equals(that.isCoordinator) :
that.isCoordinator != null) return false;
if (isReviewer != null ? !isReviewer.equals(that.isReviewer) :
that.isReviewer != null) return false;
return isTranslator != null ? isTranslator.equals(that.isTranslator) :
that.isTranslator == null;
}

@Override
public int hashCode() {
int result = username != null ? username.hashCode() : 0;
result =
31 * result +
(isCoordinator != null ? isCoordinator.hashCode() : 0);
result = 31 * result + (isReviewer != null ? isReviewer.hashCode() : 0);
result = 31 * result +
(isTranslator != null ? isTranslator.hashCode() : 0);
return result;
}
}
@@ -0,0 +1,54 @@
package org.zanata.rest.dto;

import java.io.Serializable;
import java.util.List;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonSerialize;

/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class LocalesResults implements Serializable {
public Integer totalCount;
public List<LanguageTeamSearchResult> results;

@java.beans.ConstructorProperties({ "totalCount", "results" })
public LocalesResults(final int totalCount,
final List<LanguageTeamSearchResult> results) {
this.totalCount = totalCount;
this.results = results;
}

@JsonProperty("totalCount")
public Integer getTotalCount() {
return this.totalCount;
}

@JsonProperty("results")
public List<LanguageTeamSearchResult> getResults() {
return this.results;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

LocalesResults that = (LocalesResults) o;

if (totalCount != null ? !totalCount.equals(that.totalCount) :
that.totalCount != null) return false;
return results != null ? results.equals(that.results) :
that.results == null;
}

@Override
public int hashCode() {
int result = totalCount != null ? totalCount.hashCode() : 0;
result = 31 * result + (results != null ? results.hashCode() : 0);
return result;
}
}
Expand Up @@ -18,13 +18,19 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.rest.search.dto;
package org.zanata.rest.dto;

import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import java.io.Serializable;

/**
* @author Carlos Munoz
* <a href="mailto:camunoz@redhat.com">camunoz@redhat.com</a>
*/
public abstract class SearchResult {
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public abstract class SearchResult implements Serializable {

public enum SearchResultType {
Project,
Expand All @@ -38,6 +44,7 @@ public enum SearchResultType {
private String description;
private SearchResultType type;

@JsonProperty("id")
public String getId() {
return this.id;
}
Expand All @@ -46,6 +53,7 @@ public void setId(final String id) {
this.id = id;
}

@JsonProperty("description")
public String getDescription() {
return this.description;
}
Expand All @@ -54,6 +62,7 @@ public void setDescription(final String description) {
this.description = description;
}

@JsonProperty("type")
public SearchResultType getType() {
return this.type;
}
Expand Down
@@ -1,10 +1,9 @@
package org.zanata.rest.editor.service.resource;
package org.zanata.rest.service;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
Expand All @@ -13,10 +12,9 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.deltaspike.jpa.api.transaction.Transactional;
import com.webcohesion.enunciate.metadata.rs.TypeHint;
import org.zanata.rest.dto.LocaleDetails;
import org.zanata.rest.editor.MediaTypes;
import org.zanata.rest.service.RestResource;
import org.zanata.rest.dto.LocaleMember;

/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
Expand All @@ -37,9 +35,8 @@ public interface LocalesResource extends RestResource {
* the server while performing this operation.
*/
@GET
@Produces({ MediaTypes.APPLICATION_ZANATA_LOCALES_JSON,
MediaType.APPLICATION_JSON })
public Response get(@QueryParam("filter") String filter,
@Produces(MediaType.APPLICATION_JSON)
Response get(@QueryParam("filter") String filter,
@QueryParam("sort") String fields,
@DefaultValue("1") @QueryParam("page") int page,
@DefaultValue("10") @QueryParam("sizePerPage") int sizePerPage);
Expand All @@ -49,9 +46,18 @@ public Response get(@QueryParam("filter") String filter,
*/
@GET
@Path("/locale/{localeId}")
@Produces({ MediaTypes.APPLICATION_ZANATA_LOCALES_JSON,
MediaType.APPLICATION_JSON })
public Response getDetails(@PathParam("localeId") String localeId);
@Produces(MediaType.APPLICATION_JSON)
@TypeHint(LocaleDetails.class)
Response getDetails(@PathParam("localeId") String localeId);

/**
* Retrieve locale member list
*/
@GET
@Path("/locale/{localeId}/members")
@Produces(MediaType.APPLICATION_JSON)
@TypeHint(LocaleMember[].class)
Response getMembers(@PathParam("localeId") String localeId);

/**
* Retrieves a full list of localized locales for server.
Expand All @@ -64,8 +70,8 @@ public Response get(@QueryParam("filter") String filter,
*/
@GET
@Path("/ui")
@Produces({ MediaTypes.APPLICATION_ZANATA_LOCALES_JSON,
MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
@TypeHint(LocaleDetails[].class)
Response getUITranslations();


Expand All @@ -80,8 +86,8 @@ public Response get(@QueryParam("filter") String filter,
*/
@GET
@Path("/new")
@Produces({ MediaTypes.APPLICATION_ZANATA_LOCALES_JSON,
MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
@TypeHint(LocaleDetails[].class)
Response getNewLocales(@QueryParam("filter") String filter,
@QueryParam("size") @DefaultValue("10") int size);

Expand All @@ -96,9 +102,8 @@ Response getNewLocales(@QueryParam("filter") String filter,
*/
@DELETE
@Path("/locale/{localeId}")
@Produces({ MediaTypes.APPLICATION_ZANATA_LOCALES_JSON,
MediaType.APPLICATION_JSON })
public Response delete(@PathParam("localeId") String localeId);
@Produces(MediaType.APPLICATION_JSON)
Response delete(@PathParam("localeId") String localeId);

/**
* Create a new language in Zanata
Expand All @@ -111,7 +116,7 @@ Response getNewLocales(@QueryParam("filter") String filter,
*/
@PUT
@Path("/locale")
@Produces({ MediaTypes.APPLICATION_ZANATA_LOCALES_JSON,
MediaType.APPLICATION_JSON })
public Response createLanguage(LocaleDetails localeDetails);
@Produces(MediaType.APPLICATION_JSON)
@TypeHint(LocaleDetails.class)
Response createLanguage(LocaleDetails localeDetails);
}
@@ -0,0 +1,37 @@
package org.zanata.rest.dto;

import org.junit.Test;
import org.zanata.common.LocaleId;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

/**
* @author Alex Eng<a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*/
public class LanguageTeamSearchResultTest {
@Test
public void testConstructor() {
LanguageTeamSearchResult searchResults = new LanguageTeamSearchResult();
assertThat(searchResults.getType(), equalTo(
SearchResult.SearchResultType.LanguageTeam));
}

@Test
public void testLocaleDetails() {
LocaleDetails localeDetails =
new LocaleDetails(LocaleId.DE, "German", null, null, true, true,
null);
LanguageTeamSearchResult searchResults = new LanguageTeamSearchResult();
searchResults.setLocaleDetails(localeDetails);
assertThat(searchResults.getLocaleDetails(), equalTo(localeDetails));
}

@Test
public void testMemberCount() {
long count = 100L;
LanguageTeamSearchResult searchResults = new LanguageTeamSearchResult();
searchResults.setMemberCount(count);
assertThat(searchResults.getMemberCount(), equalTo(count));
}
}

0 comments on commit 5923992

Please sign in to comment.