Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9a031447943c47f6fa5792ad6d1105722264ed00 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*******************************************************************************
 * Copyright (c) 2013 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.account.rest.internal;

import java.net.URI;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import org.eclipse.osee.account.admin.SystemRoles;
import org.eclipse.osee.account.rest.model.AccountContexts;
import org.eclipse.osee.account.rest.model.AccountDetailsData;
import org.eclipse.osee.account.rest.model.AccountInfoData;
import org.eclipse.osee.account.rest.model.AccountInput;

/**
 * @author Roberto E. Escobar
 */
public class AccountResource {

   private final AccountOps accountOps;
   private final String accountId;

   public AccountResource(AccountOps accountOps, String accountId) {
      this.accountOps = accountOps;
      this.accountId = accountId;
   }

   /**
    * Creates a new Account - all fields must be unique
    * 
    * @param accountInput Account data
    * @return new account info data
    */
   @POST
   @PermitAll
   @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
   @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
   public AccountInfoData createAccount(AccountInput accountInput) {
      return accountOps.createAccount(accountId, accountInput);
   }

   /**
    * Deletes the account
    * 
    * @return response
    * @response.representation.200.doc account status set to active
    * @response.representation.304.doc account active status not modified
    */
   @DELETE
   @RolesAllowed(SystemRoles.ROLES_ADMINISTRATOR)
   public Response deleteAccount() {
      ResponseBuilder builder;
      boolean modified = accountOps.deleteAccount(accountId);
      if (modified) {
         builder = Response.ok();
      } else {
         builder = Response.notModified();
      }
      return builder.build();
   }

   /**
    * Get account details
    * 
    * @return account details
    */
   @GET
   @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
   @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
   public AccountDetailsData getAccountDetailsData() {
      return accountOps.getAccountDetailsData(accountId);
   }

   /**
    * Get All account subscriptions
    * 
    * @return accountSubscriptions
    */
   @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
   @Path("subscriptions")
   @GET
   public Response getSubscriptions(@Context UriInfo uriInfo) {
      URI requestUri = uriInfo.getRequestUri();
      URI uri =
         UriBuilder.fromUri(requestUri).path("..").path("..").path("subscriptions").path("for-account").path(
            "{account-id}").build(accountId);
      return Response.seeOther(uri).build();
   }

   @Path(AccountContexts.ACCOUNT_PREFERENCES)
   public AccountPreferencesResource getAccountSettingsData() {
      return new AccountPreferencesResource(accountOps, accountId);
   }

   @Path(AccountContexts.ACCOUNT_ACTIVE)
   public AccountActiveResource active() {
      return new AccountActiveResource(accountOps, accountId);
   }

   @Path(AccountContexts.ACCOUNT_SESSSIONS)
   public AccountSessionsResource sessions() {
      return new AccountSessionsResource(accountOps, accountId);
   }

}

Back to the top