This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from zanata/locale-aliases
Add locale alias endpoints for project and version
- Loading branch information
Showing
6 changed files
with
311 additions
and
0 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
130 changes: 130 additions & 0 deletions
130
zanata-common-api/src/main/java/org/zanata/rest/dto/LocaleDetails.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,130 @@ | ||
/* | ||
* 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 java.io.Serializable; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import javax.xml.bind.annotation.XmlAttribute; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
import javax.xml.bind.annotation.XmlType; | ||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | ||
|
||
import org.codehaus.jackson.annotate.JsonIgnoreProperties; | ||
import org.codehaus.jackson.annotate.JsonPropertyOrder; | ||
import org.codehaus.jackson.map.annotate.JsonSerialize; | ||
import org.hibernate.validator.constraints.NotEmpty; | ||
import org.zanata.common.LocaleId; | ||
import org.zanata.common.Namespaces; | ||
|
||
@XmlType(name = "localeDetailsType") | ||
@XmlRootElement(name = "localeDetails") | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonPropertyOrder({"localeId", "displayName", "alias"}) | ||
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) | ||
public class LocaleDetails implements Serializable { | ||
|
||
private LocaleId localeId; | ||
private String displayName; | ||
private String alias; | ||
|
||
// TODO check if no args constructor is needed | ||
public LocaleDetails() { | ||
} | ||
|
||
public LocaleDetails(LocaleId localeId, String displayName, String alias) { | ||
this.localeId = localeId; | ||
this.displayName = displayName; | ||
this.alias = alias; | ||
} | ||
|
||
@XmlAttribute(name = "localeId", required = true) | ||
@XmlJavaTypeAdapter(type = LocaleId.class, value = LocaleIdAdapter.class) | ||
@NotNull | ||
public LocaleId getLocaleId() { | ||
return localeId; | ||
} | ||
|
||
public void setLocaleId(LocaleId localeId) { | ||
this.localeId = localeId; | ||
} | ||
|
||
@XmlAttribute(name = "displayName", required = true) | ||
@NotEmpty | ||
public String getDisplayName() { | ||
return displayName; | ||
} | ||
|
||
public void setDisplayName(String displayName) { | ||
this.displayName = displayName; | ||
} | ||
|
||
@XmlAttribute(name = "alias", required = false) | ||
public String getAlias() { | ||
return alias; | ||
} | ||
|
||
public void setAlias(String alias) { | ||
this.alias = alias; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return DTOUtil.toXML(this); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
String composite = localeId.toString() + displayName + alias; | ||
return composite.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (!(obj instanceof LocaleDetails)) { | ||
return false; | ||
} | ||
LocaleDetails other = (LocaleDetails) obj; | ||
if (!localeId.equals(other.localeId)) { | ||
return false; | ||
} | ||
// TODO is displayName nullable? | ||
if (!displayName.equals(other.displayName)) { | ||
return false; | ||
} | ||
if (alias == null) { | ||
if (other.alias != null) { | ||
return false; | ||
} | ||
} else if (!alias.equals(other.alias)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...a-common-api/src/main/java/org/zanata/rest/enunciate/ProjectIterationLocalesResource.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,32 @@ | ||
/* | ||
* Copyright 2015, 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.enunciate; | ||
|
||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
@Path(ProjectIterationLocalesResource.SERVICE_PATH) | ||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) | ||
interface ProjectIterationLocalesResource extends | ||
org.zanata.rest.service.ProjectIterationLocalesResource { | ||
} |
32 changes: 32 additions & 0 deletions
32
zanata-common-api/src/main/java/org/zanata/rest/enunciate/ProjectLocalesResource.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,32 @@ | ||
/* | ||
* 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.enunciate; | ||
|
||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
@Path(ProjectLocalesResource.SERVICE_PATH) | ||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) | ||
interface ProjectLocalesResource extends | ||
org.zanata.rest.service.ProjectLocalesResource { | ||
} |
55 changes: 55 additions & 0 deletions
55
zanata-common-api/src/main/java/org/zanata/rest/service/ProjectIterationLocalesResource.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,55 @@ | ||
/* | ||
* Copyright 2015, 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.service; | ||
|
||
import org.codehaus.enunciate.jaxrs.TypeHint; | ||
import org.zanata.rest.MediaTypes; | ||
import org.zanata.rest.dto.LocaleDetails; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) | ||
public interface ProjectIterationLocalesResource { | ||
public static final String SERVICE_PATH = ProjectIterationResource.SERVICE_PATH | ||
+ "/locales"; | ||
|
||
/** | ||
* Returns list of active locales for a single project-version. | ||
* | ||
* This may be the list of locales inherited from the project. | ||
* | ||
* @return | ||
* OK 200 containing the list of LocaleDetails | ||
* NOT FOUND 404 if the project-version does not exist | ||
*/ | ||
@GET | ||
// workaround for enunciate, see note in org.zanata.rest.service.ProjectResource | ||
@TypeHint(LocaleDetails[].class) | ||
@Produces({ MediaTypes.APPLICATION_ZANATA_PROJECT_LOCALES_XML, | ||
MediaTypes.APPLICATION_ZANATA_PROJECT_LOCALES_JSON, | ||
MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) | ||
public Response get(); | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
zanata-common-api/src/main/java/org/zanata/rest/service/ProjectLocalesResource.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,55 @@ | ||
/* | ||
* 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.service; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.codehaus.enunciate.jaxrs.TypeHint; | ||
import org.zanata.rest.MediaTypes; | ||
import org.zanata.rest.dto.LocaleDetails; | ||
|
||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) | ||
public interface ProjectLocalesResource { | ||
public static final String SERVICE_PATH = ProjectResource.SERVICE_PATH | ||
+ "/locales"; | ||
|
||
/** | ||
* Returns list of active locales for a single project. | ||
* | ||
* This may be the list of locales inherited from the server. | ||
* | ||
* @return | ||
* OK 200 containing the list of LocaleDetails | ||
* NOT FOUND 404 if the project does not exist | ||
*/ | ||
@GET | ||
// workaround for enunciate, see note in ProjectsResource | ||
@TypeHint(LocaleDetails[].class) | ||
@Produces({ MediaTypes.APPLICATION_ZANATA_PROJECT_LOCALES_XML, | ||
MediaTypes.APPLICATION_ZANATA_PROJECT_LOCALES_JSON, | ||
MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) | ||
public Response get(); | ||
|
||
} |