io.cloudslang.content.sitescope.services.DeleteMonitorGroupService Maven / Gradle / Ivy
/*
* (c) Copyright 2020 EntIT Software LLC, a Micro Focus company, L.P.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License v2.0 which accompany this distribution.
*
* The Apache License is available 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 io.cloudslang.content.sitescope.services;
import io.cloudslang.content.httpclient.entities.HttpClientInputs;
import io.cloudslang.content.httpclient.services.HttpClientService;
import io.cloudslang.content.sitescope.constants.Inputs;
import io.cloudslang.content.sitescope.constants.SuccessMsgs;
import io.cloudslang.content.sitescope.entities.DeleteMonitorGroupInputs;
import io.cloudslang.content.sitescope.entities.SiteScopeCommonInputs;
import io.cloudslang.content.sitescope.utils.HttpUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.utils.URIBuilder;
import org.jetbrains.annotations.NotNull;
import java.net.URISyntaxException;
import java.util.Map;
import static io.cloudslang.content.httpclient.build.auth.AuthTypes.BASIC;
import static io.cloudslang.content.sitescope.constants.Constants.*;
import static io.cloudslang.content.sitescope.services.HttpCommons.setCommonHttpInputs;
public class DeleteMonitorGroupService {
public @NotNull
Map execute(@NotNull DeleteMonitorGroupInputs deleteMonitorGroupInputs) throws Exception {
final HttpClientInputs httpClientInputs = new HttpClientInputs();
final SiteScopeCommonInputs commonInputs = deleteMonitorGroupInputs.getCommonInputs();
setCommonHttpInputs(httpClientInputs, commonInputs);
httpClientInputs.setUrl(getUrl(deleteMonitorGroupInputs));
httpClientInputs.setQueryParamsAreURLEncoded(String.valueOf(true));
httpClientInputs.setAuthType(BASIC);
httpClientInputs.setUsername(commonInputs.getUsername());
httpClientInputs.setPassword(commonInputs.getPassword());
httpClientInputs.setMethod(DELETE);
Map httpClientOutputs = new HttpClientService().execute(httpClientInputs);
return HttpUtils.convertToSitescopeResultsMap(httpClientOutputs, SuccessMsgs.DELETE_MONITOR_GROUP);
}
private String getUrl(DeleteMonitorGroupInputs inputs) throws URISyntaxException {
URIBuilder urlBuilder = new URIBuilder();
urlBuilder.setScheme(inputs.getCommonInputs().getProtocol());
urlBuilder.setHost(inputs.getCommonInputs().getHost());
urlBuilder.setPort(Integer.parseInt(inputs.getCommonInputs().getPort()));
urlBuilder.setPath(SITESCOPE_MONITORS_API + DELETE_MONITOR_GROUP_ENDPOINT);
if (StringUtils.isNotEmpty(inputs.getFullPathToGroup())) {
String fullPathToGroup = inputs.getFullPathToGroup().replace(inputs.getDelimiter(), SITE_SCOPE_DELIMITER);
urlBuilder.addParameter(Inputs.CommonInputs.FULL_PATH_TO_GROUP, fullPathToGroup);
} else if (StringUtils.isNotEmpty(inputs.getExternalId())) {
urlBuilder.addParameter(Inputs.DeleteMonitorGroupInputs.EXTERNAL_ID, inputs.getExternalId());
}
return urlBuilder.build().toString();
}
}