de.kaiserpfalzEdv.iam.core.role.PermissionBuilder.java Source code

Java tutorial

Introduction

Here is the source code for de.kaiserpfalzEdv.iam.core.role.PermissionBuilder.java

Source

/*
 * Copyright (c) 2014 Kaiserpfalz EDV-Service, Roland Lichti
 *
 * 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 de.kaiserpfalzEdv.iam.core.role;

import de.kaiserpfalzEdv.commons.NameableReadable;
import de.kaiserpfalzEdv.iam.core.base.IAMBaseObjectBuilder;
import de.kaiserpfalzEdv.iam.role.Permission;
import de.kaiserpfalzEdv.iam.role.PermissionWritable;
import org.apache.commons.lang3.builder.Builder;

import java.util.UUID;

/**
 * @author klenkes
 * @since 2014Q
 */
public class PermissionBuilder extends IAMBaseObjectBuilder<PermissionBuilder>
        implements Builder<PermissionWritable>, IAMBaseObjectBuilder.ConcreteObjectGenerator<PermissionWritable> {

    public PermissionBuilder() {
        withGenerator(this);
    }

    @Override
    public PermissionDO build() {
        PermissionDO result;

        try {
            result = generate();
        } catch (IllegalArgumentException e) {
            throw new IllegalStateException(e.getMessage(), e);
        }

        result.validate();

        return result;
    }

    @Override
    public PermissionWritable generate(UUID tenant, UUID id, NameableReadable name) {
        return new PermissionDO(tenant, id, name);
    }

    public PermissionBuilder withPermission(Permission permission) {
        withTenant(permission.getTenantId());
        withId(permission.getId());
        withName(permission.getNameable());

        return this;
    }
}