forked from aerogear/aerogear-unifiedpush-server
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
834fbf9
commit c468930
Showing
5 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
...in/java/org/jboss/aerogear/unifiedpush/rest/registry/applications/AdmVariantEndpoint.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,111 @@ | ||
/** | ||
* JBoss, Home of Professional Open Source | ||
* Copyright Red Hat, Inc., and individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.aerogear.unifiedpush.rest.registry.applications; | ||
|
||
|
||
import org.jboss.aerogear.unifiedpush.api.AdmVariant; | ||
import org.jboss.aerogear.unifiedpush.api.PushApplication; | ||
|
||
import javax.validation.ConstraintViolationException; | ||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.UriInfo; | ||
|
||
@Path("/applications/{pushAppID}/adm") | ||
public class AdmVariantEndpoint extends AbstractVariantEndpoint { | ||
|
||
|
||
@POST | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response registerAdmVariant( | ||
AdmVariant admVariant, | ||
@PathParam("pushAppID") String pushApplicationID, | ||
@Context UriInfo uriInfo) { | ||
|
||
// find the root push app | ||
PushApplication pushApp = getSearch().findByPushApplicationIDForDeveloper(pushApplicationID); | ||
|
||
if (pushApp == null) { | ||
return Response.status(Response.Status.NOT_FOUND).entity("Could not find requested PushApplicationEntity").build(); | ||
} | ||
|
||
// some validation | ||
try { | ||
validateModelClass(admVariant); | ||
} catch (ConstraintViolationException cve) { | ||
|
||
// Build and return the 400 (Bad Request) response | ||
Response.ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); | ||
|
||
return builder.build(); | ||
} | ||
|
||
// store the Adm variant: | ||
variantService.addVariant(admVariant); | ||
// add Adm variant, and merge: | ||
pushAppService.addVariant(pushApp, admVariant); | ||
|
||
return Response.created(uriInfo.getAbsolutePathBuilder().path(String.valueOf(admVariant.getVariantID())).build()).entity(admVariant).build(); | ||
} | ||
|
||
// READ | ||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response listAllAdmVariationsForPushApp(@PathParam("pushAppID") String pushApplicationID) { | ||
final PushApplication application = getSearch().findByPushApplicationIDForDeveloper(pushApplicationID); | ||
return Response.ok(getVariantsByType(application, AdmVariant.class)).build(); | ||
} | ||
|
||
// UPDATE | ||
@PUT | ||
@Path("/{admID}") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response updateAndroidVariation( | ||
@PathParam("pushAppID") String id, | ||
@PathParam("admID") String androidID, | ||
AdmVariant updatedAdmApplication) { | ||
|
||
AdmVariant admVariant = (AdmVariant) variantService.findByVariantID(androidID); | ||
if (admVariant != null) { | ||
|
||
// some validation | ||
try { | ||
validateModelClass(updatedAdmApplication); | ||
} catch (ConstraintViolationException cve) { | ||
|
||
// Build and return the 400 (Bad Request) response | ||
Response.ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); | ||
|
||
return builder.build(); | ||
} | ||
|
||
// apply updated data: | ||
admVariant.setClientId(updatedAdmApplication.getClientId()); | ||
admVariant.setClientSecret(updatedAdmApplication.getClientSecret()); | ||
admVariant.setName(updatedAdmApplication.getName()); | ||
admVariant.setDescription(updatedAdmApplication.getDescription()); | ||
variantService.updateVariant(admVariant); | ||
return Response.noContent().build(); | ||
} | ||
|
||
return Response.status(Response.Status.NOT_FOUND).entity("Could not find requested Variant").build(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
model/api/src/main/java/org/jboss/aerogear/unifiedpush/api/AdmVariant.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,52 @@ | ||
/** | ||
* JBoss, Home of Professional Open Source | ||
* Copyright Red Hat, Inc., and individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.aerogear.unifiedpush.api; | ||
|
||
|
||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Size; | ||
|
||
public class AdmVariant extends Variant { | ||
@NotNull | ||
@Size(min = 1, max = 255, message = "ClientId must be max. 255 chars long") | ||
private String clientId; | ||
|
||
@Size(min = 1, max = 255, message = "Client Secret must be max. 255 chars long") | ||
private String clientSecret; | ||
|
||
|
||
public String getClientId() { | ||
return clientId; | ||
} | ||
|
||
public void setClientId(String clientId) { | ||
this.clientId = clientId; | ||
} | ||
|
||
public String getClientSecret() { | ||
return clientSecret; | ||
} | ||
|
||
public void setClientSecret(String clientSecret) { | ||
this.clientSecret = clientSecret; | ||
} | ||
|
||
@Override | ||
public VariantType getType() { | ||
return VariantType.ADM; | ||
} | ||
} |
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