<commit_before>/*
 * Copyright © 2010 Red Hat, Inc.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package com.redhat.rhevm.api.powershell.resource;

import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;

import com.redhat.rhevm.api.model.Disk;
import com.redhat.rhevm.api.model.Disks;
import com.redhat.rhevm.api.model.DiskFormat;
import com.redhat.rhevm.api.model.DiskInterface;
import com.redhat.rhevm.api.model.DiskType;
import com.redhat.rhevm.api.model.Link;
import com.redhat.rhevm.api.common.resource.UriInfoProvider;
import com.redhat.rhevm.api.common.util.LinkHelper;
import com.redhat.rhevm.api.common.util.ReflectionHelper;
import com.redhat.rhevm.api.powershell.enums.PowerShellDiskInterface;
import com.redhat.rhevm.api.powershell.model.PowerShellDisk;
import com.redhat.rhevm.api.powershell.util.PowerShellCmd;
import com.redhat.rhevm.api.powershell.util.PowerShellParser;
import com.redhat.rhevm.api.powershell.util.PowerShellPoolMap;
import com.redhat.rhevm.api.powershell.util.PowerShellUtils;
import com.redhat.rhevm.api.resource.DevicesResource;

import static com.redhat.rhevm.api.common.util.CompletenessAssertor.validateParameters;
import static com.redhat.rhevm.api.common.util.EnumValidator.validateEnum;

public class PowerShellDisksResource
    extends PowerShellReadOnlyDisksResource
    implements DevicesResource<Disk, Disks> {

    public PowerShellDisksResource(String parentId,
                                   PowerShellPoolMap shellPools,
                                   PowerShellParser parser,
                                   String getCommand,
                                   UriInfoProvider uriProvider,
                                   HttpHeaders httpHeaders) {
        super(parentId, shellPools, parser, getCommand, uriProvider);
        setHttpHeaders(httpHeaders);
    }

    @Override
    public Response add(Disk disk) {
        Response response = null;

        validateParameters(disk, "size");
        StringBuilder buf = new StringBuilder();

        buf.append("$d = new-disk");
        buf.append(" -disksize " + Math.round((double)disk.getSize()/(1024*1024*1024)));
        if (disk.getFormat() != null) {
            DiskFormat format = validateEnum(DiskFormat.class, disk.getFormat());
            if (format != null) {
                buf.append(" -volumeformat " + format.name());
            }
        }
        if (disk.getType() != null) {
            DiskType type = validateEnum(DiskType.class, disk.getType().toUpperCase());
            if (type != null) {
                buf.append(" -disktype " + ReflectionHelper.capitalize(type.name().toLowerCase()));
            }
        }
        if (disk.getInterface() != null) {
            DiskInterface diskInterface = validateEnum(DiskInterface.class, disk.getInterface().toUpperCase());
            if (diskInterface != null) {
                buf.append(" -diskinterface " + PowerShellDiskInterface.forModel(diskInterface).name());
            }
        }
        if (disk.isSparse() != null) {<commit_msg>powershell: fix inappropriate use of validateEnum()<commit_after>/*
 * Copyright © 2010 Red Hat, Inc.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package com.redhat.rhevm.api.powershell.resource;

import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;

import com.redhat.rhevm.api.model.Disk;
import com.redhat.rhevm.api.model.Disks;
import com.redhat.rhevm.api.model.DiskFormat;
import com.redhat.rhevm.api.model.DiskInterface;
import com.redhat.rhevm.api.model.DiskType;
import com.redhat.rhevm.api.model.Link;
import com.redhat.rhevm.api.common.resource.UriInfoProvider;
import com.redhat.rhevm.api.common.util.LinkHelper;
import com.redhat.rhevm.api.common.util.ReflectionHelper;
import com.redhat.rhevm.api.powershell.enums.PowerShellDiskInterface;
import com.redhat.rhevm.api.powershell.model.PowerShellDisk;
import com.redhat.rhevm.api.powershell.util.PowerShellCmd;
import com.redhat.rhevm.api.powershell.util.PowerShellParser;
import com.redhat.rhevm.api.powershell.util.PowerShellPoolMap;
import com.redhat.rhevm.api.powershell.util.PowerShellUtils;
import com.redhat.rhevm.api.resource.DevicesResource;

import static com.redhat.rhevm.api.common.util.CompletenessAssertor.validateParameters;

public class PowerShellDisksResource
    extends PowerShellReadOnlyDisksResource
    implements DevicesResource<Disk, Disks> {

    public PowerShellDisksResource(String parentId,
                                   PowerShellPoolMap shellPools,
                                   PowerShellParser parser,
                                   String getCommand,
                                   UriInfoProvider uriProvider,
                                   HttpHeaders httpHeaders) {
        super(parentId, shellPools, parser, getCommand, uriProvider);
        setHttpHeaders(httpHeaders);
    }

    @Override
    public Response add(Disk disk) {
        Response response = null;

        validateParameters(disk, "size");
        StringBuilder buf = new StringBuilder();

        buf.append("$d = new-disk");
        buf.append(" -disksize " + Math.round((double)disk.getSize()/(1024*1024*1024)));
        if (disk.getFormat() != null) {
            DiskFormat format = DiskFormat.fromValue(disk.getFormat());
            if (format != null) {
                buf.append(" -volumeformat " + format.name());
            }
        }
        if (disk.getType() != null) {
            DiskType type = DiskType.fromValue(disk.getType());
            if (type != null) {
                buf.append(" -disktype " + ReflectionHelper.capitalize(type.name().toLowerCase()));
            }
        }
        if (disk.getInterface() != null) {
            DiskInterface diskInterface = DiskInterface.fromValue(disk.getInterface());
            if (diskInterface != null) {
                buf.append(" -diskinterface " + PowerShellDiskInterface.forModel(diskInterface).name());
            }
        }
        if (disk.isSparse() != null) {
{'fraction_non_alphanumeric': 0.10300880304821969, 'fraction_numerical': 0.007620549205097885, 'mean_word_length': 2.9015889287544847, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4745695', 'n_tokens_mistral': 2228, 'n_tokens_neox': 2143, 'n_words': 527}