All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.rocketbase.commons.test.model.AppInviteTestEntity Maven / Gradle / Ivy

There is a newer version: 4.4.1
Show newest version
package io.rocketbase.commons.test.model;

import com.google.common.collect.ImmutableMap;
import io.rocketbase.commons.model.AppInviteEntity;
import lombok.*;

import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(of = {"id"})
public class AppInviteTestEntity implements AppInviteEntity {

    private String id;

    private String invitor;

    private String message;

    private String firstName;

    private String lastName;

    private String email;

    private List roles;

    @Builder.Default
    private Map keyValueMap = new HashMap<>();


    private Instant created;

    private Instant expiration;

    @Override
    public AppInviteTestEntity clone() {
        Map copyedKeyValueMap = getKeyValueMap() != null ? new HashMap<>(ImmutableMap.copyOf(getKeyValueMap())) : null;
        return AppInviteTestEntity.builder()
                .id(getId())
                .invitor(getInvitor())
                .message(getMessage())
                .email(getEmail())
                .roles(getRoles() != null ? getRoles().stream().map(r -> String.valueOf(r)).collect(Collectors.toList()) : null)
                .firstName(getFirstName())
                .lastName(getLastName())
                .created(getCreated())
                .expiration(getExpiration())
                .keyValueMap(copyedKeyValueMap)
                .build();
    }

    @Override
    public AppInviteEntity addKeyValue(String key, String value) {
        checkKeyValue(key, value);
        keyValueMap.put(key.toLowerCase(), value);
        return this;
    }

    @Override
    public void removeKeyValue(String key) {
        keyValueMap.remove(key.toLowerCase());
    }

    @Override
    public Map getKeyValues() {
        return keyValueMap != null ? ImmutableMap.copyOf(keyValueMap) : null;
    }

    @Override
    public boolean hasKeyValue(String key) {
        return keyValueMap != null && key != null && keyValueMap.containsKey(key.toLowerCase());
    }

    @Override
    public String getKeyValue(String key) {
        return keyValueMap != null && key != null ? keyValueMap.getOrDefault(key.toLowerCase(), null) : null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy