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 */
030public class GetPools extends Event<List<VmPool>> {
031
032    private String name;
033    private String user;
034    private List<String> roles = Collections.emptyList();
035
036    /**
037     * Return only the pool with the given name.
038     *
039     * @param name the name
040     * @return the returns the vms
041     */
042    public GetPools withName(String name) {
043        this.name = name;
044        return this;
045    }
046
047    /**
048     * Return only {@link VmPool}s that are accessible by
049     * the given user or roles.
050     *
051     * @param user the user
052     * @param roles the roles
053     * @return the event 
054     */
055    public GetPools accessibleFor(String user, List<String> roles) {
056        this.user = user;
057        this.roles = roles;
058        return this;
059    }
060
061    /**
062     * Returns the name filter criterion, if set.
063     *
064     * @return the optional
065     */
066    public Optional<String> name() {
067        return Optional.ofNullable(name);
068    }
069
070    /**
071     * Returns the user filter criterion, if set.
072     *
073     * @return the optional
074     */
075    public Optional<String> forUser() {
076        return Optional.ofNullable(user);
077    }
078
079    /**
080     * Returns the roles criterion.
081     *
082     * @return the list
083     */
084    public List<String> forRoles() {
085        return roles;
086    }
087}