Skip to content

Commit

Permalink
Add User Profile entities
Browse files Browse the repository at this point in the history
  • Loading branch information
MDeLuise authored and Coduz committed Mar 28, 2023
1 parent b0e7600 commit 484bb49
Show file tree
Hide file tree
Showing 15 changed files with 421 additions and 1 deletion.
2 changes: 2 additions & 0 deletions console/web/src/main/resources/locator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@

<api>org.eclipse.kapua.service.user.UserFactory</api>
<api>org.eclipse.kapua.service.user.UserService</api>
<api>org.eclipse.kapua.service.user.profile.UserProfileService</api>
<api>org.eclipse.kapua.service.user.profile.UserProfileFactory</api>

<api>org.eclipse.kapua.job.engine.JobEngineService</api>
<api>org.eclipse.kapua.job.engine.JobEngineFactory</api>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.app.api.resources.v1.resources;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.app.api.core.model.ScopeId;
import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.service.user.profile.UserProfile;
import org.eclipse.kapua.service.user.profile.UserProfileService;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("{scopeId}/user/profile")
public class UserProfiles extends AbstractKapuaResource {
private final KapuaLocator locator = KapuaLocator.getInstance();
private final UserProfileService userProfileService = locator.getService(UserProfileService.class);


@PUT
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response changeUserProfile(@PathParam("scopeId") ScopeId scopeId, UserProfile userProfile) throws KapuaException {
userProfileService.changeUserProfile(userProfile);
return returnOk();
}

@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public UserProfile getUserProfile(@PathParam("scopeId") ScopeId scopeId) throws KapuaException {
return userProfileService.getUserProfile();
}
}

6 changes: 6 additions & 0 deletions rest-api/resources/src/main/resources/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ paths:
$ref: './userCredentials/userCredentials-scopeId.yaml#/paths/~1{scopeId}~1user~1credentials~1password'
/{scopeId}/user/credentials/{credentialId}/_reset:
$ref: './userCredentials/userCredentials-scopeId-credentialId-_reset.yaml#/paths/~1{scopeId}~1user~1credentials~1{credentialId}~1_reset'
### User Profile ###
/{scopeId}/user/profile/:
$ref: './userProfile/userProfile-scopeId.yaml#/paths/~1{scopeId}~1user~1profile~1'

components:
parameters:
Expand Down Expand Up @@ -939,6 +942,9 @@ components:
$ref: './userCredentials/userCredentials.yaml#/components/schemas/passwordChangeRequest'
passwordResetRequest:
$ref: './userCredentials/userCredentials.yaml#/components/schemas/passwordResetRequest'
### User Profile Entities ###
userProfile:
$ref: './userProfile/userProfile.yaml#/components/schemas/userProfile'
requestBodies:
kapuaQuery:
description: An object to specify Query options
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
openapi: 3.0.2

info:
title: Everyware Cloud REST API - User Profile
version: '1.0'
contact:
name: Eurotech
url: https://www.eurotech.com

paths:

/{scopeId}/user/profile/:
get:
tags:
- User Profile
summary: Get the User Profile
operationId: userProfileGet
parameters:
- $ref: '../openapi.yaml#/components/parameters/scopeId'
responses:
200:
description: The desired user profile
content:
application/json:
schema:
$ref: './userProfile.yaml#/components/schemas/userProfile'
401:
$ref: '../openapi.yaml#/components/responses/unauthenticated'
403:
$ref: '../openapi.yaml#/components/responses/subjectUnauthorized'
404:
$ref: '../openapi.yaml#/components/responses/entityNotFound'
500:
$ref: '../openapi.yaml#/components/responses/kapuaError'
put:
tags:
- User Profile
summary: Change the User Profile
operationId: userProfileUpdate
parameters:
- $ref: '../openapi.yaml#/components/parameters/scopeId'
requestBody:
content:
application/json:
schema:
$ref: '../openapi.yaml#/components/schemas/userProfile'
responses:
200:
description: The user profile has been updated
401:
$ref: '../openapi.yaml#/components/responses/unauthenticated'
403:
$ref: '../openapi.yaml#/components/responses/subjectUnauthorized'
500:
$ref: '../openapi.yaml#/components/responses/kapuaError'
description: Change logged user profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
openapi: 3.0.2

info:
title: Everyware Cloud REST API - User Profile
version: '1.0'
contact:
name: Eurotech
url: https://www.eurotech.com

paths: {}

components:
schemas:
userProfile:
allOf:
- description: The user profile
type: object
properties:
displayName:
type: string
phoneNumber:
type: string
email:
type: string
example:
displayName: "Foo42"
phoneNumber: "424202424"
email: "foo@bar.com"
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@
import org.eclipse.kapua.service.user.UserListResult;
import org.eclipse.kapua.service.user.UserQuery;
import org.eclipse.kapua.service.user.UserXmlRegistry;
import org.eclipse.kapua.service.user.profile.UserProfile;
import org.eclipse.kapua.service.user.profile.UserProfileXmlRegistry;
import org.eclipse.persistence.jaxb.JAXBContextFactory;
import org.eclipse.persistence.jaxb.MarshallerProperties;

Expand Down Expand Up @@ -695,6 +697,10 @@ public JaxbContextResolver() {
PasswordResetRequest.class,
UserCredentialsXmlRegistry.class,

// User Profile
UserProfile.class,
UserProfileXmlRegistry.class,

// KapuaEvent
ServiceEvent.class,
EventStoreRecordCreator.class,
Expand Down
2 changes: 2 additions & 0 deletions rest-api/web/src/main/resources/locator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@

<api>org.eclipse.kapua.service.user.UserFactory</api>
<api>org.eclipse.kapua.service.user.UserService</api>
<api>org.eclipse.kapua.service.user.profile.UserProfileService</api>
<api>org.eclipse.kapua.service.user.profile.UserProfileFactory</api>

<api>org.eclipse.kapua.service.stream.StreamService</api>

Expand Down
7 changes: 6 additions & 1 deletion rest-api/web/src/main/resources/shiro.ini
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,9 @@ kapuaAuthcAccessToken = org.eclipse.kapua.app.api.core.auth.KapuaTokenAuthentica
# User Credentials
/v1/*/user/credentials.json = kapuaAuthcAccessToken
/v1/*/user/credentials.xml = kapuaAuthcAccessToken
/v1/*/user/credentials/** = kapuaAuthcAccessToken
/v1/*/user/credentials/** = kapuaAuthcAccessToken

# User Profile
/v1/*/user/profile.json = kapuaAuthcAccessToken
/v1/*/user/profile.xml = kapuaAuthcAccessToken
/v1/*/user/profile/** = kapuaAuthcAccessToken
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*******************************************************************************
* Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.user.profile;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(factoryClass = UserProfileXmlRegistry.class, factoryMethod = "newUserProfile")
public interface UserProfile {
String TYPE = "userProfile";

@XmlElement(name = "displayName")
String getDisplayName();

void setDisplayName(String displayName);

@XmlElement(name = "phoneNumber")
String getPhoneNumber();

void setPhoneNumber(String phoneNumber);

@XmlElement(name = "email")
String getEmail();

void setEmail(String email);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.user.profile;

import org.eclipse.kapua.model.KapuaObjectFactory;

public interface UserProfileFactory extends KapuaObjectFactory {
UserProfile newUserProfile();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.user.profile;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.service.KapuaService;

public interface UserProfileService extends KapuaService {

void changeUserProfile(UserProfile userProfile) throws KapuaException;

UserProfile getUserProfile() throws KapuaException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.user.profile;

import org.eclipse.kapua.locator.KapuaLocator;

import javax.xml.bind.annotation.XmlRegistry;

@XmlRegistry
public class UserProfileXmlRegistry {
private final KapuaLocator locator = KapuaLocator.getInstance();
private final UserProfileFactory userProfileFactory = locator.getFactory(UserProfileFactory.class);


public UserProfile newUserProfile() {
return userProfileFactory.newUserProfile();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.user.internal.profile;

import org.eclipse.kapua.locator.KapuaProvider;
import org.eclipse.kapua.service.user.profile.UserProfile;
import org.eclipse.kapua.service.user.profile.UserProfileFactory;

@KapuaProvider
public class UserProfileFactoryImpl implements UserProfileFactory {
@Override
public UserProfile newUserProfile() {
return new UserProfileImpl();
}
}

0 comments on commit 484bb49

Please sign in to comment.