001/*
002 * VM-Operator
003 * Copyright (C) 2024 Michael N. Lipp
004 * 
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
017 */
018
019package org.jdrupes.vmoperator.manager.events;
020
021import java.util.Collections;
022import java.util.List;
023import java.util.Optional;
024import org.jdrupes.vmoperator.common.VmPool;
025import org.jgrapes.core.Event;
026
027/**
028 * Gets the known pools' definitions.
029 */
030@SuppressWarnings("PMD.DataClass")
031public class GetPools extends Event<List<VmPool>> {
032
033    private String name;
034    private String user;
035    private List<String> roles = Collections.emptyList();
036
037    /**
038     * Return only the pool with the given name.
039     *
040     * @param name the name
041     * @return the returns the vms
042     */
043    public GetPools withName(String name) {
044        this.name = name;
045        return this;
046    }
047
048    /**
049     * Return only {@link VmPool}s that are accessible by
050     * the given user or roles.
051     *
052     * @param user the user
053     * @param roles the roles
054     * @return the event 
055     */
056    public GetPools accessibleFor(String user, List<String> roles) {
057        this.user = user;
058        this.roles = roles;
059        return this;
060    }
061
062    /**
063     * Returns the name filter criterion, if set.
064     *
065     * @return the optional
066     */
067    public Optional<String> name() {
068        return Optional.ofNullable(name);
069    }
070
071    /**
072     * Returns the user filter criterion, if set.
073     *
074     * @return the optional
075     */
076    public Optional<String> forUser() {
077        return Optional.ofNullable(user);
078    }
079
080    /**
081     * Returns the roles criterion.
082     *
083     * @return the list
084     */
085    public List<String> forRoles() {
086        return roles;
087    }
088}