/* * Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file 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 com.amazon.example.pojo; import com.amazon.example.service.AbstractService; import io.quarkus.runtime.annotations.RegisterForReflection; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import java.util.Map; import java.util.Objects; @RegisterForReflection public class User { private String userId; private String userName; private String firstName; private String lastName; private int age; public User() { } public User(String userId, String userName, String firstName, String lastName, int age) { this.userId = userId; this.userName = userName; this.firstName = firstName; this.lastName = lastName; this.age = age; } public static User from(Map item) { User user = new User(); if (item != null && !item.isEmpty()) { user.setUserId(item.get(AbstractService.USER_ID_COL).s()); user.setUserName(item.get(AbstractService.USER_USERNAME_COL).s()); user.setFirstName(item.get(AbstractService.USER_FIRSTNAME_COL).s()); user.setLastName(item.get(AbstractService.USER_LASTNAME_COL).s()); user.setAge(Integer.parseInt(item.get(AbstractService.USER_AGE_COL).n())); } return user; } public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; User user = (User) o; return userId.equals(user.userId); } @Override public int hashCode() { return Objects.hash(userId); } @Override public String toString() { return "UserPojo{" + "userId=" + userId + ", userName='" + userName + '\'' + ", firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + ", age=" + age + '}'; } }