<commit_before>/*
 * Copyright 2016 <NAME>.
 *
 * 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.chrthms.hmatic4j.core.commands.impl.init;

import de.chrthms.hmatic4j.core.commands.impl.AbstractCommand;
import de.chrthms.hmatic4j.core.exceptions.HMExecutionException;
import de.chrthms.hmatic4j.core.exceptions.HMUnsupportedException;
import de.chrthms.hmatic4j.core.helpers.ConcatHelper;
import de.chrthms.hmatic4j.core.impl.AbstractConnectionImpl;

/**
 *
 * @author christian
 */
public abstract class AbstractInit extends AbstractCommand {

    private String logicRpcServerAddress = null;
    private String logicRpcServerPort = null;
    
    protected abstract String getIterfaceId() throws HMExecutionException;
    
    private String getLogicRpcServerUrl() throws HMExecutionException {
        if (logicRpcServerAddress == null) throw new HMExecutionException("An URL for the rpc server (logic side) must be set!");
        
        if (logicRpcServerPort != null) {
            return ConcatHelper.concatAddressPort(logicRpcServerAddress, logicRpcServerPort);
        } else {
            return logicRpcServerAddress;
        }
    }
    
    public AbstractInit logicRpcServerAddress(String logicRpcServerAddress) {
        this.logicRpcServerAddress = logicRpcServerAddress;
        return this;
    }
    
    public AbstractInit logicRpcServerPort(String logicRpcServerPort) {
        this.logicRpcServerPort = logicRpcServerPort;
        return this;
    }
    
    @Override
    public void execute(AbstractConnectionImpl connection) throws HMUnsupportedException, HMExecutionException {
        final String interfaceId = getIterfaceId();
        
        if (interfaceId != null) {
            connection.executeRpcCall(getMethodName(), getLogicRpcServerUrl(), interfaceId);            
        } else {
            connection.executeRpcCall(getMethodName(), getLogicRpcServerUrl());            
        }        
    }

    @Override
    public Object singleResult(AbstractConnectionImpl connection) throws HMUnsupportedException, HMExecutionException {
        throw new HMUnsupportedException();
    }<commit_msg>add "path" method for init commands<commit_after>/*
 * Copyright 2016 <NAME>.
 *
 * 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.chrthms.hmatic4j.core.commands.impl.init;

import de.chrthms.hmatic4j.core.commands.impl.AbstractCommand;
import de.chrthms.hmatic4j.core.exceptions.HMExecutionException;
import de.chrthms.hmatic4j.core.exceptions.HMUnsupportedException;
import de.chrthms.hmatic4j.core.helpers.ConcatHelper;
import de.chrthms.hmatic4j.core.impl.AbstractConnectionImpl;

/**
 *
 * @author christian
 */
public abstract class AbstractInit extends AbstractCommand {

    private String logicRpcServerAddress = null;
    private String logicRpcServerPort = null;
    private String logicRpcServerPath = "/";
    
    protected abstract String getIterfaceId() throws HMExecutionException;
    
    private String getLogicRpcServerUrl() throws HMExecutionException {
        if (logicRpcServerAddress == null) throw new HMExecutionException("An URL for the rpc server (logic side) must be set!");
        
        StringBuilder serverUrl = new StringBuilder();
        
        if (logicRpcServerPort != null) {
            serverUrl.append(ConcatHelper.concatAddressPort(logicRpcServerAddress, logicRpcServerPort));
        } else {
            serverUrl.append(logicRpcServerAddress);
        }
        
        if (!logicRpcServerPath.startsWith("/")) {
            serverUrl.append("/");
        }
        
        serverUrl.append(logicRpcServerPath);
        return serverUrl.toString();
    }
    
    public AbstractInit logicRpcServerAddress(String logicRpcServerAddress) {
        this.logicRpcServerAddress = logicRpcServerAddress;
        return this;
    }
    
    public AbstractInit logicRpcServerPort(String logicRpcServerPort) {
        this.logicRpcServerPort = logicRpcServerPort;
        return this;
    }
    
    public AbstractInit logicRpcServerPath(String logicRpcServerPath) {
        this.logicRpcServerPath = logicRpcServerPath;
        return this;
    }
    
    @Override
    public void execute(AbstractConnectionImpl connection) throws HMUnsupportedException, HMExecutionException {
        final String interfaceId = getIterfaceId();
        
        if (interfaceId != null) {
            connection.executeRpcCall(getMethodName(), getLogicRpcServerUrl(), interfaceId);            
        } else {
            connection.executeRpcCall(getMethodName(), getLogicRpcServerUrl());            
        }        
    }

    @Override
    public Object singleResult(AbstractConnectionImpl connection) throws HMUnsupportedException, HMExecutionException {
        throw new HMUnsupportedException();
    }
{'fraction_non_alphanumeric': 0.07500858221764505, 'fraction_numerical': 0.004806041881222108, 'mean_word_length': 3.262618873445501, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7061880', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1531, 'n_words': 412}