Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #25 from zanata/locale-aliases
Browse files Browse the repository at this point in the history
Add locale alias endpoints for project and version
  • Loading branch information
davidmason committed Feb 17, 2015
2 parents bb9f2c7 + 2fc1a87 commit 20e900b
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 0 deletions.
Expand Up @@ -34,6 +34,13 @@ public String toString() {
public static final String APPLICATION_ZANATA_PROJECT_JSON =
APPLICATION_ZANATA_PROJECT + JSON;

public static final String APPLICATION_ZANATA_PROJECT_LOCALES =
APPLICATION_ZANATA_PROJECT + ".locales";
public static final String APPLICATION_ZANATA_PROJECT_LOCALES_XML =
APPLICATION_ZANATA_PROJECT_LOCALES + XML;
public static final String APPLICATION_ZANATA_PROJECT_LOCALES_JSON =
APPLICATION_ZANATA_PROJECT_LOCALES + JSON;

public static final String APPLICATION_ZANATA_PROJECTS =
APPLICATION_VND_ZANATA + ".projects";
public static final String APPLICATION_ZANATA_PROJECTS_XML =
Expand Down
130 changes: 130 additions & 0 deletions zanata-common-api/src/main/java/org/zanata/rest/dto/LocaleDetails.java
@@ -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;
}

}
@@ -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 {
}
@@ -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 {
}
@@ -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();

}
@@ -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();

}

0 comments on commit 20e900b

Please sign in to comment.