repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
JetBrains/teamcity-deployer-plugin
deploy-runner-server/src/test/java/jetbrains/buildServer/deployer/server/SSHExecRunTypeTest.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // }
import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.serverSide.InvalidProperty; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.testng.annotations.Test; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server; /** * Created by Nikita.Skvortsov * Date: 12/18/12, 4:15 PM */ @Test public class SSHExecRunTypeTest extends DeployerRunTypeTest { SSHExecRunType myRunType; @Override protected void createRunType(RunTypeRegistry registry, PluginDescriptor descriptor) { myRunType = new SSHExecRunType(registry, descriptor); } public void testGetDescription() throws Exception { assertEquals(myRunType.getDescription(), "Runner able to execute commands over SSH"); } public void testDescribeEmptyParameters() throws Exception { //noinspection unchecked myRunType.describeParameters(Collections.EMPTY_MAP); } public void testValidParameters() throws Exception { Map<String, String> parameters = new HashMap<String, String>();
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // } // Path: deploy-runner-server/src/test/java/jetbrains/buildServer/deployer/server/SSHExecRunTypeTest.java import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.serverSide.InvalidProperty; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.testng.annotations.Test; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server; /** * Created by Nikita.Skvortsov * Date: 12/18/12, 4:15 PM */ @Test public class SSHExecRunTypeTest extends DeployerRunTypeTest { SSHExecRunType myRunType; @Override protected void createRunType(RunTypeRegistry registry, PluginDescriptor descriptor) { myRunType = new SSHExecRunType(registry, descriptor); } public void testGetDescription() throws Exception { assertEquals(myRunType.getDescription(), "Runner able to execute commands over SSH"); } public void testDescribeEmptyParameters() throws Exception { //noinspection unchecked myRunType.describeParameters(Collections.EMPTY_MAP); } public void testValidParameters() throws Exception { Map<String, String> parameters = new HashMap<String, String>();
parameters.put(DeployerRunnerConstants.PARAM_TARGET_URL, "targethost");
JetBrains/teamcity-deployer-plugin
deploy-runner-server/src/test/java/jetbrains/buildServer/deployer/server/SSHExecRunTypeTest.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // }
import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.serverSide.InvalidProperty; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.testng.annotations.Test; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server; /** * Created by Nikita.Skvortsov * Date: 12/18/12, 4:15 PM */ @Test public class SSHExecRunTypeTest extends DeployerRunTypeTest { SSHExecRunType myRunType; @Override protected void createRunType(RunTypeRegistry registry, PluginDescriptor descriptor) { myRunType = new SSHExecRunType(registry, descriptor); } public void testGetDescription() throws Exception { assertEquals(myRunType.getDescription(), "Runner able to execute commands over SSH"); } public void testDescribeEmptyParameters() throws Exception { //noinspection unchecked myRunType.describeParameters(Collections.EMPTY_MAP); } public void testValidParameters() throws Exception { Map<String, String> parameters = new HashMap<String, String>(); parameters.put(DeployerRunnerConstants.PARAM_TARGET_URL, "targethost");
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // } // Path: deploy-runner-server/src/test/java/jetbrains/buildServer/deployer/server/SSHExecRunTypeTest.java import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.serverSide.InvalidProperty; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.testng.annotations.Test; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server; /** * Created by Nikita.Skvortsov * Date: 12/18/12, 4:15 PM */ @Test public class SSHExecRunTypeTest extends DeployerRunTypeTest { SSHExecRunType myRunType; @Override protected void createRunType(RunTypeRegistry registry, PluginDescriptor descriptor) { myRunType = new SSHExecRunType(registry, descriptor); } public void testGetDescription() throws Exception { assertEquals(myRunType.getDescription(), "Runner able to execute commands over SSH"); } public void testDescribeEmptyParameters() throws Exception { //noinspection unchecked myRunType.describeParameters(Collections.EMPTY_MAP); } public void testValidParameters() throws Exception { Map<String, String> parameters = new HashMap<String, String>(); parameters.put(DeployerRunnerConstants.PARAM_TARGET_URL, "targethost");
parameters.put(SSHRunnerConstants.PARAM_AUTH_METHOD, SSHRunnerConstants.AUTH_METHOD_USERNAME_PWD);
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/cargo/CargoDeployerRunnerInfo.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // }
import jetbrains.buildServer.agent.AgentBuildRunnerInfo; import jetbrains.buildServer.agent.BuildAgentConfiguration; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import org.jetbrains.annotations.NotNull;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.cargo; class CargoDeployerRunnerInfo implements AgentBuildRunnerInfo { @NotNull @Override public String getType() {
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/cargo/CargoDeployerRunnerInfo.java import jetbrains.buildServer.agent.AgentBuildRunnerInfo; import jetbrains.buildServer.agent.BuildAgentConfiguration; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import org.jetbrains.annotations.NotNull; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.cargo; class CargoDeployerRunnerInfo implements AgentBuildRunnerInfo { @NotNull @Override public String getType() {
return DeployerRunnerConstants.CARGO_RUN_TYPE;
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/smb/SmbDeployerRunner.java
// Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/base/BaseDeployerRunner.java // public abstract class BaseDeployerRunner implements AgentBuildRunner { // protected final ExtensionHolder myExtensionHolder; // // public BaseDeployerRunner(@NotNull final ExtensionHolder extensionHolder) { // myExtensionHolder = extensionHolder; // } // // @NotNull // @Override // public BuildProcess createBuildProcess(@NotNull final AgentRunningBuild runningBuild, // @NotNull final BuildRunnerContext context) throws RunBuildException { // // final Map<String, String> runnerParameters = context.getRunnerParameters(); // final String username = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_USERNAME)); // final String password = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_PASSWORD)); // final String target = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_TARGET_URL)); // final String sourcePaths = runnerParameters.get(DeployerRunnerConstants.PARAM_SOURCE_PATH); // // final Collection<ArtifactsPreprocessor> preprocessors = myExtensionHolder.getExtensions(ArtifactsPreprocessor.class); // // final ArtifactsBuilder builder = new ArtifactsBuilder(); // builder.setPreprocessors(preprocessors); // builder.setBaseDir(runningBuild.getCheckoutDirectory()); // builder.setArtifactsPaths(sourcePaths); // // final List<ArtifactsCollection> artifactsCollections = builder.build(); // // return getDeployerProcess(context, username, password, target, artifactsCollections); // } // // protected abstract BuildProcess getDeployerProcess(@NotNull final BuildRunnerContext context, // @NotNull final String username, // @NotNull final String password, // @NotNull final String target, // @NotNull final List<ArtifactsCollection> artifactsCollections) throws RunBuildException; // // @NotNull // @Override // public abstract AgentBuildRunnerInfo getRunnerInfo(); // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SMBRunnerConstants.java // public class SMBRunnerConstants { // public static final String DNS_ONLY_NAME_RESOLUTION = "jetbrains.buildServer.deployer.smb.dns_only"; // public static final String SHOULD_ENFORCE_SMB1 = "teamcity.deployer.smb.enforceSMBv1"; // }
import com.intellij.openapi.util.SystemInfo; import jetbrains.buildServer.ExtensionHolder; import jetbrains.buildServer.agent.AgentBuildRunnerInfo; import jetbrains.buildServer.agent.BuildProcess; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.agent.plugins.beans.PluginDescriptor; import jetbrains.buildServer.deployer.agent.base.BaseDeployerRunner; import jetbrains.buildServer.deployer.common.SMBRunnerConstants; import jetbrains.buildServer.serverSide.TeamCityProperties; import jetbrains.buildServer.util.CollectionsUtil; import jetbrains.buildServer.util.Converter; import jetbrains.buildServer.util.StringUtil; import org.jetbrains.annotations.NotNull; import java.io.File; import java.lang.reflect.Constructor; import java.net.URL; import java.net.URLClassLoader; import java.util.Arrays; import java.util.List;
final String actualUsername; if (username.indexOf('\\') > -1) { domain = username.substring(0, username.indexOf('\\')); actualUsername = username.substring(username.indexOf('\\') + 1); } else { domain = ""; actualUsername = username; } if (shouldEnforceSMBv1(context)) { context.getBuild().getBuildLogger().warning("Enforced deprecated SMB v1 usage"); return getSmbV1Process(context, actualUsername, password, domain, target, artifactsCollections); } if (SystemInfo.isJavaVersionAtLeast("1.7.0")) { context.getBuild().getBuildLogger().message("Using SMB v2/v3 protocol"); return getSmbV2Process(context, actualUsername, password, domain, target,artifactsCollections); } else { context.getBuild().getBuildLogger().warning("Falling back to deprecated SMB v1. Update jvm to 1.7+ to use SMB v2"); return getSmbV1Process(context, actualUsername, password, domain, target, artifactsCollections); } } catch (Exception e) { throw new RuntimeException(e); } } private boolean shouldEnforceSMBv1(@NotNull final BuildRunnerContext context) { boolean shouldEnforceOnBuild =
// Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/base/BaseDeployerRunner.java // public abstract class BaseDeployerRunner implements AgentBuildRunner { // protected final ExtensionHolder myExtensionHolder; // // public BaseDeployerRunner(@NotNull final ExtensionHolder extensionHolder) { // myExtensionHolder = extensionHolder; // } // // @NotNull // @Override // public BuildProcess createBuildProcess(@NotNull final AgentRunningBuild runningBuild, // @NotNull final BuildRunnerContext context) throws RunBuildException { // // final Map<String, String> runnerParameters = context.getRunnerParameters(); // final String username = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_USERNAME)); // final String password = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_PASSWORD)); // final String target = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_TARGET_URL)); // final String sourcePaths = runnerParameters.get(DeployerRunnerConstants.PARAM_SOURCE_PATH); // // final Collection<ArtifactsPreprocessor> preprocessors = myExtensionHolder.getExtensions(ArtifactsPreprocessor.class); // // final ArtifactsBuilder builder = new ArtifactsBuilder(); // builder.setPreprocessors(preprocessors); // builder.setBaseDir(runningBuild.getCheckoutDirectory()); // builder.setArtifactsPaths(sourcePaths); // // final List<ArtifactsCollection> artifactsCollections = builder.build(); // // return getDeployerProcess(context, username, password, target, artifactsCollections); // } // // protected abstract BuildProcess getDeployerProcess(@NotNull final BuildRunnerContext context, // @NotNull final String username, // @NotNull final String password, // @NotNull final String target, // @NotNull final List<ArtifactsCollection> artifactsCollections) throws RunBuildException; // // @NotNull // @Override // public abstract AgentBuildRunnerInfo getRunnerInfo(); // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SMBRunnerConstants.java // public class SMBRunnerConstants { // public static final String DNS_ONLY_NAME_RESOLUTION = "jetbrains.buildServer.deployer.smb.dns_only"; // public static final String SHOULD_ENFORCE_SMB1 = "teamcity.deployer.smb.enforceSMBv1"; // } // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/smb/SmbDeployerRunner.java import com.intellij.openapi.util.SystemInfo; import jetbrains.buildServer.ExtensionHolder; import jetbrains.buildServer.agent.AgentBuildRunnerInfo; import jetbrains.buildServer.agent.BuildProcess; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.agent.plugins.beans.PluginDescriptor; import jetbrains.buildServer.deployer.agent.base.BaseDeployerRunner; import jetbrains.buildServer.deployer.common.SMBRunnerConstants; import jetbrains.buildServer.serverSide.TeamCityProperties; import jetbrains.buildServer.util.CollectionsUtil; import jetbrains.buildServer.util.Converter; import jetbrains.buildServer.util.StringUtil; import org.jetbrains.annotations.NotNull; import java.io.File; import java.lang.reflect.Constructor; import java.net.URL; import java.net.URLClassLoader; import java.util.Arrays; import java.util.List; final String actualUsername; if (username.indexOf('\\') > -1) { domain = username.substring(0, username.indexOf('\\')); actualUsername = username.substring(username.indexOf('\\') + 1); } else { domain = ""; actualUsername = username; } if (shouldEnforceSMBv1(context)) { context.getBuild().getBuildLogger().warning("Enforced deprecated SMB v1 usage"); return getSmbV1Process(context, actualUsername, password, domain, target, artifactsCollections); } if (SystemInfo.isJavaVersionAtLeast("1.7.0")) { context.getBuild().getBuildLogger().message("Using SMB v2/v3 protocol"); return getSmbV2Process(context, actualUsername, password, domain, target,artifactsCollections); } else { context.getBuild().getBuildLogger().warning("Falling back to deprecated SMB v1. Update jvm to 1.7+ to use SMB v2"); return getSmbV1Process(context, actualUsername, password, domain, target, artifactsCollections); } } catch (Exception e) { throw new RuntimeException(e); } } private boolean shouldEnforceSMBv1(@NotNull final BuildRunnerContext context) { boolean shouldEnforceOnBuild =
StringUtil.isTrue(context.getBuild().getSharedConfigParameters().get(SMBRunnerConstants.SHOULD_ENFORCE_SMB1));
JetBrains/teamcity-deployer-plugin
deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/FtpDeployerPropertiesProcessor.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // }
import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.FTPRunnerConstants; import jetbrains.buildServer.serverSide.InvalidProperty; import java.util.Collection; import java.util.Map;
package jetbrains.buildServer.deployer.server; public class FtpDeployerPropertiesProcessor extends DeployerPropertiesProcessor { @Override public Collection<InvalidProperty> process(Map<String, String> properties) {
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // } // Path: deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/FtpDeployerPropertiesProcessor.java import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.FTPRunnerConstants; import jetbrains.buildServer.serverSide.InvalidProperty; import java.util.Collection; import java.util.Map; package jetbrains.buildServer.deployer.server; public class FtpDeployerPropertiesProcessor extends DeployerPropertiesProcessor { @Override public Collection<InvalidProperty> process(Map<String, String> properties) {
if (!FTPRunnerConstants.AUTH_METHOD_USER_PWD.equals(properties.get(FTPRunnerConstants.PARAM_AUTH_METHOD))) {
JetBrains/teamcity-deployer-plugin
deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/FtpDeployerPropertiesProcessor.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // }
import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.FTPRunnerConstants; import jetbrains.buildServer.serverSide.InvalidProperty; import java.util.Collection; import java.util.Map;
package jetbrains.buildServer.deployer.server; public class FtpDeployerPropertiesProcessor extends DeployerPropertiesProcessor { @Override public Collection<InvalidProperty> process(Map<String, String> properties) { if (!FTPRunnerConstants.AUTH_METHOD_USER_PWD.equals(properties.get(FTPRunnerConstants.PARAM_AUTH_METHOD))) {
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // } // Path: deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/FtpDeployerPropertiesProcessor.java import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.FTPRunnerConstants; import jetbrains.buildServer.serverSide.InvalidProperty; import java.util.Collection; import java.util.Map; package jetbrains.buildServer.deployer.server; public class FtpDeployerPropertiesProcessor extends DeployerPropertiesProcessor { @Override public Collection<InvalidProperty> process(Map<String, String> properties) { if (!FTPRunnerConstants.AUTH_METHOD_USER_PWD.equals(properties.get(FTPRunnerConstants.PARAM_AUTH_METHOD))) {
properties.remove(DeployerRunnerConstants.PARAM_USERNAME);
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ssh/SSHExecRunnerInfo.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // }
import jetbrains.buildServer.agent.AgentBuildRunnerInfo; import jetbrains.buildServer.agent.BuildAgentConfiguration; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import org.jetbrains.annotations.NotNull;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.ssh; class SSHExecRunnerInfo implements AgentBuildRunnerInfo { @NotNull @Override public String getType() {
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // } // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ssh/SSHExecRunnerInfo.java import jetbrains.buildServer.agent.AgentBuildRunnerInfo; import jetbrains.buildServer.agent.BuildAgentConfiguration; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import org.jetbrains.annotations.NotNull; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.ssh; class SSHExecRunnerInfo implements AgentBuildRunnerInfo { @NotNull @Override public String getType() {
return SSHRunnerConstants.SSH_EXEC_RUN_TYPE;
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/base/BaseDeployerRunner.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // }
import jetbrains.buildServer.ExtensionHolder; import jetbrains.buildServer.RunBuildException; import jetbrains.buildServer.agent.*; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsBuilder; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.util.StringUtil; import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.List; import java.util.Map;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.base; /** * Created by Nikita.Skvortsov * Date: 10/1/12, 10:44 AM */ public abstract class BaseDeployerRunner implements AgentBuildRunner { protected final ExtensionHolder myExtensionHolder; public BaseDeployerRunner(@NotNull final ExtensionHolder extensionHolder) { myExtensionHolder = extensionHolder; } @NotNull @Override public BuildProcess createBuildProcess(@NotNull final AgentRunningBuild runningBuild, @NotNull final BuildRunnerContext context) throws RunBuildException { final Map<String, String> runnerParameters = context.getRunnerParameters();
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/base/BaseDeployerRunner.java import jetbrains.buildServer.ExtensionHolder; import jetbrains.buildServer.RunBuildException; import jetbrains.buildServer.agent.*; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsBuilder; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.util.StringUtil; import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.List; import java.util.Map; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.base; /** * Created by Nikita.Skvortsov * Date: 10/1/12, 10:44 AM */ public abstract class BaseDeployerRunner implements AgentBuildRunner { protected final ExtensionHolder myExtensionHolder; public BaseDeployerRunner(@NotNull final ExtensionHolder extensionHolder) { myExtensionHolder = extensionHolder; } @NotNull @Override public BuildProcess createBuildProcess(@NotNull final AgentRunningBuild runningBuild, @NotNull final BuildRunnerContext context) throws RunBuildException { final Map<String, String> runnerParameters = context.getRunnerParameters();
final String username = StringUtil.emptyIfNull(runnerParameters.get(DeployerRunnerConstants.PARAM_USERNAME));
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ssh/SSHExecRunner.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // }
import jetbrains.buildServer.RunBuildException; import jetbrains.buildServer.agent.*; import jetbrains.buildServer.agent.ssh.AgentRunningBuildSshKeyManager; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.util.StringUtil; import org.jetbrains.annotations.NotNull; import java.util.Map;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.ssh; public class SSHExecRunner implements AgentBuildRunner { private final InternalPropertiesHolder myInternalProperties; @NotNull private final AgentRunningBuildSshKeyManager mySshKeyManager; public SSHExecRunner(@NotNull final InternalPropertiesHolder holder, @NotNull final AgentRunningBuildSshKeyManager sshKeyManager) { myInternalProperties = holder; mySshKeyManager = sshKeyManager; } @NotNull public BuildProcess createBuildProcess(@NotNull AgentRunningBuild runningBuild, @NotNull final BuildRunnerContext context) throws RunBuildException { final SSHSessionProvider provider = new SSHSessionProvider(context, myInternalProperties, mySshKeyManager); final Map<String, String> parameters = context.getRunnerParameters();
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // } // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ssh/SSHExecRunner.java import jetbrains.buildServer.RunBuildException; import jetbrains.buildServer.agent.*; import jetbrains.buildServer.agent.ssh.AgentRunningBuildSshKeyManager; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.util.StringUtil; import org.jetbrains.annotations.NotNull; import java.util.Map; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.ssh; public class SSHExecRunner implements AgentBuildRunner { private final InternalPropertiesHolder myInternalProperties; @NotNull private final AgentRunningBuildSshKeyManager mySshKeyManager; public SSHExecRunner(@NotNull final InternalPropertiesHolder holder, @NotNull final AgentRunningBuildSshKeyManager sshKeyManager) { myInternalProperties = holder; mySshKeyManager = sshKeyManager; } @NotNull public BuildProcess createBuildProcess(@NotNull AgentRunningBuild runningBuild, @NotNull final BuildRunnerContext context) throws RunBuildException { final SSHSessionProvider provider = new SSHSessionProvider(context, myInternalProperties, mySshKeyManager); final Map<String, String> parameters = context.getRunnerParameters();
final String command = StringUtil.notNullize(parameters.get(SSHRunnerConstants.PARAM_COMMAND));
JetBrains/teamcity-deployer-plugin
deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/cargo/CargoDeployerRunType.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // }
import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.serverSide.RunType; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server.cargo; public class CargoDeployerRunType extends RunType { private final PluginDescriptor myDescriptor; public CargoDeployerRunType(@NotNull final RunTypeRegistry registry, @NotNull final PluginDescriptor descriptor) { registry.registerRunType(this); myDescriptor = descriptor; } @NotNull @Override public String getType() {
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // Path: deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/cargo/CargoDeployerRunType.java import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.serverSide.RunType; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server.cargo; public class CargoDeployerRunType extends RunType { private final PluginDescriptor myDescriptor; public CargoDeployerRunType(@NotNull final RunTypeRegistry registry, @NotNull final PluginDescriptor descriptor) { registry.registerRunType(this); myDescriptor = descriptor; } @NotNull @Override public String getType() {
return DeployerRunnerConstants.CARGO_RUN_TYPE;
JetBrains/teamcity-deployer-plugin
deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/SSHExecRunType.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // }
import com.intellij.openapi.util.text.StringUtil; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.serverSide.InvalidProperty; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.serverSide.RunType; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; import java.util.*;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server; public class SSHExecRunType extends RunType { private final PluginDescriptor myDescriptor; public SSHExecRunType(@NotNull final RunTypeRegistry registry, @NotNull final PluginDescriptor descriptor) { registry.registerRunType(this); myDescriptor = descriptor; } @NotNull @Override public String getType() {
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // } // Path: deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/SSHExecRunType.java import com.intellij.openapi.util.text.StringUtil; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.serverSide.InvalidProperty; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.serverSide.RunType; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; import java.util.*; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server; public class SSHExecRunType extends RunType { private final PluginDescriptor myDescriptor; public SSHExecRunType(@NotNull final RunTypeRegistry registry, @NotNull final PluginDescriptor descriptor) { registry.registerRunType(this); myDescriptor = descriptor; } @NotNull @Override public String getType() {
return SSHRunnerConstants.SSH_EXEC_RUN_TYPE;
JetBrains/teamcity-deployer-plugin
deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/SSHExecRunType.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // }
import com.intellij.openapi.util.text.StringUtil; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.serverSide.InvalidProperty; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.serverSide.RunType; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; import java.util.*;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server; public class SSHExecRunType extends RunType { private final PluginDescriptor myDescriptor; public SSHExecRunType(@NotNull final RunTypeRegistry registry, @NotNull final PluginDescriptor descriptor) { registry.registerRunType(this); myDescriptor = descriptor; } @NotNull @Override public String getType() { return SSHRunnerConstants.SSH_EXEC_RUN_TYPE; } @Override public String getDisplayName() { return "SSH Exec"; } @Override public String getDescription() { return "Runner able to execute commands over SSH"; } @Override public PropertiesProcessor getRunnerPropertiesProcessor() { return new SSHDeployerPropertiesProcessor() { @Override public Collection<InvalidProperty> process(Map<String, String> properties) { final Collection<InvalidProperty> invalidProperties = new HashSet<InvalidProperty>();
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // } // Path: deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/SSHExecRunType.java import com.intellij.openapi.util.text.StringUtil; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.serverSide.InvalidProperty; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.serverSide.RunType; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; import java.util.*; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server; public class SSHExecRunType extends RunType { private final PluginDescriptor myDescriptor; public SSHExecRunType(@NotNull final RunTypeRegistry registry, @NotNull final PluginDescriptor descriptor) { registry.registerRunType(this); myDescriptor = descriptor; } @NotNull @Override public String getType() { return SSHRunnerConstants.SSH_EXEC_RUN_TYPE; } @Override public String getDisplayName() { return "SSH Exec"; } @Override public String getDescription() { return "Runner able to execute commands over SSH"; } @Override public PropertiesProcessor getRunnerPropertiesProcessor() { return new SSHDeployerPropertiesProcessor() { @Override public Collection<InvalidProperty> process(Map<String, String> properties) { final Collection<InvalidProperty> invalidProperties = new HashSet<InvalidProperty>();
if (jetbrains.buildServer.util.StringUtil.isEmptyOrSpaces(properties.get(DeployerRunnerConstants.PARAM_USERNAME)) &&
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/ftp/DockerFtpBuildProcessAdapterTest.java
// Path: deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/BaseDeployerTest.java // public class BaseDeployerTest extends BaseTestCase { // protected static final int DEPLOYER_DEFAULT_PORT = 55369; // // protected File getTestResource(String fileName) { // final String pathInBuildAgentModule = "src/test/resources/" + fileName; // File file = new File(pathInBuildAgentModule); // if (!file.exists()) { // file = new File("deploy-runner-agent/" + pathInBuildAgentModule); // } // return file; // } // // protected DeployTestUtils.TempFilesFactory createTempFilesFactory() { // return new DeployTestUtils.TempFilesFactory() { // @Override // public File createTempFile(int size) throws IOException { // return BaseDeployerTest.this.createTempFile(size); // } // }; // } // } // // Path: deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/util/DeployTestUtils.java // public class DeployTestUtils { // public static void runProcess(final BuildProcess process, final int timeout) throws RunBuildException { // process.start(); // new WaitFor(timeout) { // @Override // protected boolean condition() { // return process.isFinished(); // } // }; // assertThat(process.isFinished()).describedAs("Failed to finish test in time").isTrue(); // assertThat(process.waitFor()).isEqualTo(BuildFinishedStatus.FINISHED_SUCCESS); // } // // public static ArtifactsCollection buildArtifactsCollection(final TempFilesFactory tempFiles, String... destinationDirs) throws IOException { // // final Map<File, String> filePathMap = new HashMap<File, String>(); // String dirTo = "dirTo"; // for (String destinationDir : destinationDirs) { // dirTo = destinationDir; // final File content = tempFiles.createTempFile(100); // filePathMap.put(content, destinationDir); // } // return new ArtifactsCollection("dirFrom/**", dirTo, filePathMap); // } // // public static void assertCollectionsTransferred(File remoteBase, List<ArtifactsCollection> artifactsCollections) throws IOException { // // for (ArtifactsCollection artifactsCollection : artifactsCollections) { // for (Map.Entry<File, String> fileStringEntry : artifactsCollection.getFilePathMap().entrySet()) { // final File source = fileStringEntry.getKey(); // final String relativePath = fileStringEntry.getValue(); // final String targetPath = relativePath + (StringUtil.isNotEmpty(relativePath) ? File.separator : "") + source.getName(); // final File target; // if (new File(targetPath).isAbsolute()) { // target = new File(targetPath); // } else { // target = new File(remoteBase, targetPath); // } // assertTrue(target.exists(), "Destination file [" + targetPath + "] does not exist"); // assertEquals(FileUtil.readText(target), FileUtil.readText(source), "wrong content"); // } // } // } // // public interface TempFilesFactory { // File createTempFile(int size) throws IOException; // } // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // }
import jetbrains.buildServer.agent.*; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.deployer.agent.BaseDeployerTest; import jetbrains.buildServer.deployer.agent.util.DeployTestUtils; import jetbrains.buildServer.deployer.common.FTPRunnerConstants; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.io.IOUtils; import org.jmock.Expectations; import org.jmock.Mockery; import org.testcontainers.containers.BindMode; import org.testcontainers.containers.FixedHostPortGenericContainer; import org.testcontainers.containers.GenericContainer; import org.testng.annotations.*; import java.io.*; import java.util.*; import java.util.zip.GZIPInputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipFile;
final File workingDir = createTempDir(); mockeryCtx.checking(new Expectations() {{ allowing(myContext).getWorkingDirectory(); will(returnValue(workingDir)); allowing(myContext).getBuild(); will(returnValue(build)); allowing(myContext).getRunnerParameters(); will(returnValue(myRunnerParameters)); allowing(build).getBuildLogger(); will(returnValue(logger)); allowing(build).getSharedConfigParameters(); will(returnValue(mySharedConfigParameters)); }}); } @AfterClass public void tearDownClass() { ftp.stop(); } @AfterMethod @Override public void tearDown() throws Exception { super.tearDown(); } @Test public void testSimpleTransfer() throws Exception { myRunnerParameters.put(FTPRunnerConstants.PARAM_SSL_MODE, "2");
// Path: deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/BaseDeployerTest.java // public class BaseDeployerTest extends BaseTestCase { // protected static final int DEPLOYER_DEFAULT_PORT = 55369; // // protected File getTestResource(String fileName) { // final String pathInBuildAgentModule = "src/test/resources/" + fileName; // File file = new File(pathInBuildAgentModule); // if (!file.exists()) { // file = new File("deploy-runner-agent/" + pathInBuildAgentModule); // } // return file; // } // // protected DeployTestUtils.TempFilesFactory createTempFilesFactory() { // return new DeployTestUtils.TempFilesFactory() { // @Override // public File createTempFile(int size) throws IOException { // return BaseDeployerTest.this.createTempFile(size); // } // }; // } // } // // Path: deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/util/DeployTestUtils.java // public class DeployTestUtils { // public static void runProcess(final BuildProcess process, final int timeout) throws RunBuildException { // process.start(); // new WaitFor(timeout) { // @Override // protected boolean condition() { // return process.isFinished(); // } // }; // assertThat(process.isFinished()).describedAs("Failed to finish test in time").isTrue(); // assertThat(process.waitFor()).isEqualTo(BuildFinishedStatus.FINISHED_SUCCESS); // } // // public static ArtifactsCollection buildArtifactsCollection(final TempFilesFactory tempFiles, String... destinationDirs) throws IOException { // // final Map<File, String> filePathMap = new HashMap<File, String>(); // String dirTo = "dirTo"; // for (String destinationDir : destinationDirs) { // dirTo = destinationDir; // final File content = tempFiles.createTempFile(100); // filePathMap.put(content, destinationDir); // } // return new ArtifactsCollection("dirFrom/**", dirTo, filePathMap); // } // // public static void assertCollectionsTransferred(File remoteBase, List<ArtifactsCollection> artifactsCollections) throws IOException { // // for (ArtifactsCollection artifactsCollection : artifactsCollections) { // for (Map.Entry<File, String> fileStringEntry : artifactsCollection.getFilePathMap().entrySet()) { // final File source = fileStringEntry.getKey(); // final String relativePath = fileStringEntry.getValue(); // final String targetPath = relativePath + (StringUtil.isNotEmpty(relativePath) ? File.separator : "") + source.getName(); // final File target; // if (new File(targetPath).isAbsolute()) { // target = new File(targetPath); // } else { // target = new File(remoteBase, targetPath); // } // assertTrue(target.exists(), "Destination file [" + targetPath + "] does not exist"); // assertEquals(FileUtil.readText(target), FileUtil.readText(source), "wrong content"); // } // } // } // // public interface TempFilesFactory { // File createTempFile(int size) throws IOException; // } // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // } // Path: deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/ftp/DockerFtpBuildProcessAdapterTest.java import jetbrains.buildServer.agent.*; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.deployer.agent.BaseDeployerTest; import jetbrains.buildServer.deployer.agent.util.DeployTestUtils; import jetbrains.buildServer.deployer.common.FTPRunnerConstants; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.io.IOUtils; import org.jmock.Expectations; import org.jmock.Mockery; import org.testcontainers.containers.BindMode; import org.testcontainers.containers.FixedHostPortGenericContainer; import org.testcontainers.containers.GenericContainer; import org.testng.annotations.*; import java.io.*; import java.util.*; import java.util.zip.GZIPInputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; final File workingDir = createTempDir(); mockeryCtx.checking(new Expectations() {{ allowing(myContext).getWorkingDirectory(); will(returnValue(workingDir)); allowing(myContext).getBuild(); will(returnValue(build)); allowing(myContext).getRunnerParameters(); will(returnValue(myRunnerParameters)); allowing(build).getBuildLogger(); will(returnValue(logger)); allowing(build).getSharedConfigParameters(); will(returnValue(mySharedConfigParameters)); }}); } @AfterClass public void tearDownClass() { ftp.stop(); } @AfterMethod @Override public void tearDown() throws Exception { super.tearDown(); } @Test public void testSimpleTransfer() throws Exception { myRunnerParameters.put(FTPRunnerConstants.PARAM_SSL_MODE, "2");
myArtifactsCollections.add(DeployTestUtils.buildArtifactsCollection(createTempFilesFactory(),
JetBrains/teamcity-deployer-plugin
deploy-runner-agent-smb/src/main/java/jetbrains/buildServer/deployer/agent/smb/SMBBuildProcessAdapter.java
// Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/DeployerAgentUtils.java // public class DeployerAgentUtils { // public static void logBuildProblem(BuildProgressLogger logger, String message) { // logger.logBuildProblem(BuildProblemData // .createBuildProblem(String.valueOf(message.hashCode()), // DeployerRunnerConstants.BUILD_PROBLEM_TYPE, // "Deployment problem: " + message)); // } // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/SyncBuildProcessAdapter.java // public abstract class SyncBuildProcessAdapter extends BuildProcessAdapter { // protected final BuildProgressLogger myLogger; // private volatile boolean hasFinished; // private volatile BuildFinishedStatus statusCode; // private volatile boolean isInterrupted; // // // public SyncBuildProcessAdapter(@NotNull final BuildProgressLogger logger) { // myLogger = logger; // hasFinished = false; // statusCode = null; // } // // // @Override // public void interrupt() { // isInterrupted = true; // } // // @Override // public boolean isInterrupted() { // return isInterrupted; // } // // @Override // public boolean isFinished() { // return hasFinished; // } // // @NotNull // @Override // public BuildFinishedStatus waitFor() throws RunBuildException { // while (!isInterrupted() && !hasFinished) { // try { // Thread.sleep(1000); // } catch (InterruptedException e) { // throw new RunBuildException(e); // } // } // return hasFinished ? statusCode : BuildFinishedStatus.INTERRUPTED; // } // // @Override // public void start() throws RunBuildException { // try { // statusCode = runProcess(); // hasFinished = true; // } catch (UploadInterruptedException e) { // hasFinished = false; // } // } // // /** // * @return true is process finished successfully // */ // protected abstract BuildFinishedStatus runProcess(); // // protected void checkIsInterrupted() throws UploadInterruptedException { // if (isInterrupted()) throw new UploadInterruptedException(); // } // // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/UploadInterruptedException.java // public class UploadInterruptedException extends RuntimeException { // // }
import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.text.StringUtil; import jcifs.smb.NtlmPasswordAuthentication; import jcifs.smb.SmbFile; import jetbrains.buildServer.agent.BuildFinishedStatus; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.deployer.agent.DeployerAgentUtils; import jetbrains.buildServer.deployer.agent.SyncBuildProcessAdapter; import jetbrains.buildServer.deployer.agent.UploadInterruptedException; import jetbrains.buildServer.log.Loggers; import jetbrains.buildServer.util.FileUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.util.List; import java.util.Map;
} else if (!myTarget.startsWith(SMB)) { targetWithProtocol = SMB + myTarget; } else { targetWithProtocol = myTarget; } // Share and directories names require trailing / if (!targetWithProtocol.endsWith("/")) { targetWithProtocol = targetWithProtocol + "/"; } targetWithProtocol = targetWithProtocol.replaceAll("\\\\", "/"); NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(myDomain == null ? "" : myDomain, myUsername, myPassword); final String settingsString = "Trying to connect with following parameters:\n" + "username=[" + myUsername + "]\n" + "domain=[" + (myDomain == null ? "" : myDomain) + "]\n" + "target=[" + targetWithProtocol + "]"; try { Loggers.AGENT.debug(settingsString); myLogger.message("Starting upload via SMB to " + myTarget); SmbFile destinationDir = new SmbFile(targetWithProtocol, auth); for (ArtifactsCollection artifactsCollection : myArtifactsCollections) { final int numOfUploadedFiles = upload(artifactsCollection.getFilePathMap(), destinationDir); myLogger.message("Uploaded [" + numOfUploadedFiles + "] files for [" + artifactsCollection.getSourcePath() + "] pattern"); } return BuildFinishedStatus.FINISHED_SUCCESS;
// Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/DeployerAgentUtils.java // public class DeployerAgentUtils { // public static void logBuildProblem(BuildProgressLogger logger, String message) { // logger.logBuildProblem(BuildProblemData // .createBuildProblem(String.valueOf(message.hashCode()), // DeployerRunnerConstants.BUILD_PROBLEM_TYPE, // "Deployment problem: " + message)); // } // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/SyncBuildProcessAdapter.java // public abstract class SyncBuildProcessAdapter extends BuildProcessAdapter { // protected final BuildProgressLogger myLogger; // private volatile boolean hasFinished; // private volatile BuildFinishedStatus statusCode; // private volatile boolean isInterrupted; // // // public SyncBuildProcessAdapter(@NotNull final BuildProgressLogger logger) { // myLogger = logger; // hasFinished = false; // statusCode = null; // } // // // @Override // public void interrupt() { // isInterrupted = true; // } // // @Override // public boolean isInterrupted() { // return isInterrupted; // } // // @Override // public boolean isFinished() { // return hasFinished; // } // // @NotNull // @Override // public BuildFinishedStatus waitFor() throws RunBuildException { // while (!isInterrupted() && !hasFinished) { // try { // Thread.sleep(1000); // } catch (InterruptedException e) { // throw new RunBuildException(e); // } // } // return hasFinished ? statusCode : BuildFinishedStatus.INTERRUPTED; // } // // @Override // public void start() throws RunBuildException { // try { // statusCode = runProcess(); // hasFinished = true; // } catch (UploadInterruptedException e) { // hasFinished = false; // } // } // // /** // * @return true is process finished successfully // */ // protected abstract BuildFinishedStatus runProcess(); // // protected void checkIsInterrupted() throws UploadInterruptedException { // if (isInterrupted()) throw new UploadInterruptedException(); // } // // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/UploadInterruptedException.java // public class UploadInterruptedException extends RuntimeException { // // } // Path: deploy-runner-agent-smb/src/main/java/jetbrains/buildServer/deployer/agent/smb/SMBBuildProcessAdapter.java import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.text.StringUtil; import jcifs.smb.NtlmPasswordAuthentication; import jcifs.smb.SmbFile; import jetbrains.buildServer.agent.BuildFinishedStatus; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.deployer.agent.DeployerAgentUtils; import jetbrains.buildServer.deployer.agent.SyncBuildProcessAdapter; import jetbrains.buildServer.deployer.agent.UploadInterruptedException; import jetbrains.buildServer.log.Loggers; import jetbrains.buildServer.util.FileUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.util.List; import java.util.Map; } else if (!myTarget.startsWith(SMB)) { targetWithProtocol = SMB + myTarget; } else { targetWithProtocol = myTarget; } // Share and directories names require trailing / if (!targetWithProtocol.endsWith("/")) { targetWithProtocol = targetWithProtocol + "/"; } targetWithProtocol = targetWithProtocol.replaceAll("\\\\", "/"); NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(myDomain == null ? "" : myDomain, myUsername, myPassword); final String settingsString = "Trying to connect with following parameters:\n" + "username=[" + myUsername + "]\n" + "domain=[" + (myDomain == null ? "" : myDomain) + "]\n" + "target=[" + targetWithProtocol + "]"; try { Loggers.AGENT.debug(settingsString); myLogger.message("Starting upload via SMB to " + myTarget); SmbFile destinationDir = new SmbFile(targetWithProtocol, auth); for (ArtifactsCollection artifactsCollection : myArtifactsCollections) { final int numOfUploadedFiles = upload(artifactsCollection.getFilePathMap(), destinationDir); myLogger.message("Uploaded [" + numOfUploadedFiles + "] files for [" + artifactsCollection.getSourcePath() + "] pattern"); } return BuildFinishedStatus.FINISHED_SUCCESS;
} catch (UploadInterruptedException e) {
JetBrains/teamcity-deployer-plugin
deploy-runner-agent-smb/src/main/java/jetbrains/buildServer/deployer/agent/smb/SMBBuildProcessAdapter.java
// Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/DeployerAgentUtils.java // public class DeployerAgentUtils { // public static void logBuildProblem(BuildProgressLogger logger, String message) { // logger.logBuildProblem(BuildProblemData // .createBuildProblem(String.valueOf(message.hashCode()), // DeployerRunnerConstants.BUILD_PROBLEM_TYPE, // "Deployment problem: " + message)); // } // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/SyncBuildProcessAdapter.java // public abstract class SyncBuildProcessAdapter extends BuildProcessAdapter { // protected final BuildProgressLogger myLogger; // private volatile boolean hasFinished; // private volatile BuildFinishedStatus statusCode; // private volatile boolean isInterrupted; // // // public SyncBuildProcessAdapter(@NotNull final BuildProgressLogger logger) { // myLogger = logger; // hasFinished = false; // statusCode = null; // } // // // @Override // public void interrupt() { // isInterrupted = true; // } // // @Override // public boolean isInterrupted() { // return isInterrupted; // } // // @Override // public boolean isFinished() { // return hasFinished; // } // // @NotNull // @Override // public BuildFinishedStatus waitFor() throws RunBuildException { // while (!isInterrupted() && !hasFinished) { // try { // Thread.sleep(1000); // } catch (InterruptedException e) { // throw new RunBuildException(e); // } // } // return hasFinished ? statusCode : BuildFinishedStatus.INTERRUPTED; // } // // @Override // public void start() throws RunBuildException { // try { // statusCode = runProcess(); // hasFinished = true; // } catch (UploadInterruptedException e) { // hasFinished = false; // } // } // // /** // * @return true is process finished successfully // */ // protected abstract BuildFinishedStatus runProcess(); // // protected void checkIsInterrupted() throws UploadInterruptedException { // if (isInterrupted()) throw new UploadInterruptedException(); // } // // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/UploadInterruptedException.java // public class UploadInterruptedException extends RuntimeException { // // }
import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.text.StringUtil; import jcifs.smb.NtlmPasswordAuthentication; import jcifs.smb.SmbFile; import jetbrains.buildServer.agent.BuildFinishedStatus; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.deployer.agent.DeployerAgentUtils; import jetbrains.buildServer.deployer.agent.SyncBuildProcessAdapter; import jetbrains.buildServer.deployer.agent.UploadInterruptedException; import jetbrains.buildServer.log.Loggers; import jetbrains.buildServer.util.FileUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.util.List; import java.util.Map;
} // Share and directories names require trailing / if (!targetWithProtocol.endsWith("/")) { targetWithProtocol = targetWithProtocol + "/"; } targetWithProtocol = targetWithProtocol.replaceAll("\\\\", "/"); NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(myDomain == null ? "" : myDomain, myUsername, myPassword); final String settingsString = "Trying to connect with following parameters:\n" + "username=[" + myUsername + "]\n" + "domain=[" + (myDomain == null ? "" : myDomain) + "]\n" + "target=[" + targetWithProtocol + "]"; try { Loggers.AGENT.debug(settingsString); myLogger.message("Starting upload via SMB to " + myTarget); SmbFile destinationDir = new SmbFile(targetWithProtocol, auth); for (ArtifactsCollection artifactsCollection : myArtifactsCollections) { final int numOfUploadedFiles = upload(artifactsCollection.getFilePathMap(), destinationDir); myLogger.message("Uploaded [" + numOfUploadedFiles + "] files for [" + artifactsCollection.getSourcePath() + "] pattern"); } return BuildFinishedStatus.FINISHED_SUCCESS; } catch (UploadInterruptedException e) { myLogger.warning("SMB upload interrupted."); return BuildFinishedStatus.FINISHED_FAILED; } catch (IOException e) {
// Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/DeployerAgentUtils.java // public class DeployerAgentUtils { // public static void logBuildProblem(BuildProgressLogger logger, String message) { // logger.logBuildProblem(BuildProblemData // .createBuildProblem(String.valueOf(message.hashCode()), // DeployerRunnerConstants.BUILD_PROBLEM_TYPE, // "Deployment problem: " + message)); // } // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/SyncBuildProcessAdapter.java // public abstract class SyncBuildProcessAdapter extends BuildProcessAdapter { // protected final BuildProgressLogger myLogger; // private volatile boolean hasFinished; // private volatile BuildFinishedStatus statusCode; // private volatile boolean isInterrupted; // // // public SyncBuildProcessAdapter(@NotNull final BuildProgressLogger logger) { // myLogger = logger; // hasFinished = false; // statusCode = null; // } // // // @Override // public void interrupt() { // isInterrupted = true; // } // // @Override // public boolean isInterrupted() { // return isInterrupted; // } // // @Override // public boolean isFinished() { // return hasFinished; // } // // @NotNull // @Override // public BuildFinishedStatus waitFor() throws RunBuildException { // while (!isInterrupted() && !hasFinished) { // try { // Thread.sleep(1000); // } catch (InterruptedException e) { // throw new RunBuildException(e); // } // } // return hasFinished ? statusCode : BuildFinishedStatus.INTERRUPTED; // } // // @Override // public void start() throws RunBuildException { // try { // statusCode = runProcess(); // hasFinished = true; // } catch (UploadInterruptedException e) { // hasFinished = false; // } // } // // /** // * @return true is process finished successfully // */ // protected abstract BuildFinishedStatus runProcess(); // // protected void checkIsInterrupted() throws UploadInterruptedException { // if (isInterrupted()) throw new UploadInterruptedException(); // } // // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/UploadInterruptedException.java // public class UploadInterruptedException extends RuntimeException { // // } // Path: deploy-runner-agent-smb/src/main/java/jetbrains/buildServer/deployer/agent/smb/SMBBuildProcessAdapter.java import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.text.StringUtil; import jcifs.smb.NtlmPasswordAuthentication; import jcifs.smb.SmbFile; import jetbrains.buildServer.agent.BuildFinishedStatus; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.deployer.agent.DeployerAgentUtils; import jetbrains.buildServer.deployer.agent.SyncBuildProcessAdapter; import jetbrains.buildServer.deployer.agent.UploadInterruptedException; import jetbrains.buildServer.log.Loggers; import jetbrains.buildServer.util.FileUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.util.List; import java.util.Map; } // Share and directories names require trailing / if (!targetWithProtocol.endsWith("/")) { targetWithProtocol = targetWithProtocol + "/"; } targetWithProtocol = targetWithProtocol.replaceAll("\\\\", "/"); NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(myDomain == null ? "" : myDomain, myUsername, myPassword); final String settingsString = "Trying to connect with following parameters:\n" + "username=[" + myUsername + "]\n" + "domain=[" + (myDomain == null ? "" : myDomain) + "]\n" + "target=[" + targetWithProtocol + "]"; try { Loggers.AGENT.debug(settingsString); myLogger.message("Starting upload via SMB to " + myTarget); SmbFile destinationDir = new SmbFile(targetWithProtocol, auth); for (ArtifactsCollection artifactsCollection : myArtifactsCollections) { final int numOfUploadedFiles = upload(artifactsCollection.getFilePathMap(), destinationDir); myLogger.message("Uploaded [" + numOfUploadedFiles + "] files for [" + artifactsCollection.getSourcePath() + "] pattern"); } return BuildFinishedStatus.FINISHED_SUCCESS; } catch (UploadInterruptedException e) { myLogger.warning("SMB upload interrupted."); return BuildFinishedStatus.FINISHED_FAILED; } catch (IOException e) {
DeployerAgentUtils.logBuildProblem(myLogger, e.getMessage());
JetBrains/teamcity-deployer-plugin
deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/FtpDeployerRunType.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // }
import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.FTPRunnerConstants; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.serverSide.RunType; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server; public class FtpDeployerRunType extends RunType { private final PluginDescriptor myDescriptor; public FtpDeployerRunType(@NotNull final RunTypeRegistry registry, @NotNull final PluginDescriptor descriptor) { registry.registerRunType(this); myDescriptor = descriptor; } @NotNull @Override public String getType() {
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // } // Path: deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/FtpDeployerRunType.java import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.FTPRunnerConstants; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.serverSide.RunType; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server; public class FtpDeployerRunType extends RunType { private final PluginDescriptor myDescriptor; public FtpDeployerRunType(@NotNull final RunTypeRegistry registry, @NotNull final PluginDescriptor descriptor) { registry.registerRunType(this); myDescriptor = descriptor; } @NotNull @Override public String getType() {
return DeployerRunnerConstants.FTP_RUN_TYPE;
JetBrains/teamcity-deployer-plugin
deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/FtpDeployerRunType.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // }
import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.FTPRunnerConstants; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.serverSide.RunType; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map;
} @Override public String getDisplayName() { return "FTP Upload"; } @Override public String getDescription() { return "Deploys files/directories via FTP"; } @Override public PropertiesProcessor getRunnerPropertiesProcessor() { return new FtpDeployerPropertiesProcessor(); } @Override public String getEditRunnerParamsJspFilePath() { return myDescriptor.getPluginResourcesPath() + "editFtpDeployerParams.jsp"; } @Override public String getViewRunnerParamsJspFilePath() { return myDescriptor.getPluginResourcesPath() + "viewFtpDeployerParams.jsp"; } @Override public Map<String, String> getDefaultRunnerProperties() { final HashMap<String, String> defaults = new HashMap<String, String>();
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // } // Path: deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/FtpDeployerRunType.java import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.FTPRunnerConstants; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.serverSide.RunType; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; } @Override public String getDisplayName() { return "FTP Upload"; } @Override public String getDescription() { return "Deploys files/directories via FTP"; } @Override public PropertiesProcessor getRunnerPropertiesProcessor() { return new FtpDeployerPropertiesProcessor(); } @Override public String getEditRunnerParamsJspFilePath() { return myDescriptor.getPluginResourcesPath() + "editFtpDeployerParams.jsp"; } @Override public String getViewRunnerParamsJspFilePath() { return myDescriptor.getPluginResourcesPath() + "viewFtpDeployerParams.jsp"; } @Override public Map<String, String> getDefaultRunnerProperties() { final HashMap<String, String> defaults = new HashMap<String, String>();
defaults.put(FTPRunnerConstants.PARAM_FTP_MODE, "PASSIVE");
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ftp/FtpBuildProcessAdapter.java
// Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/SyncBuildProcessAdapter.java // public abstract class SyncBuildProcessAdapter extends BuildProcessAdapter { // protected final BuildProgressLogger myLogger; // private volatile boolean hasFinished; // private volatile BuildFinishedStatus statusCode; // private volatile boolean isInterrupted; // // // public SyncBuildProcessAdapter(@NotNull final BuildProgressLogger logger) { // myLogger = logger; // hasFinished = false; // statusCode = null; // } // // // @Override // public void interrupt() { // isInterrupted = true; // } // // @Override // public boolean isInterrupted() { // return isInterrupted; // } // // @Override // public boolean isFinished() { // return hasFinished; // } // // @NotNull // @Override // public BuildFinishedStatus waitFor() throws RunBuildException { // while (!isInterrupted() && !hasFinished) { // try { // Thread.sleep(1000); // } catch (InterruptedException e) { // throw new RunBuildException(e); // } // } // return hasFinished ? statusCode : BuildFinishedStatus.INTERRUPTED; // } // // @Override // public void start() throws RunBuildException { // try { // statusCode = runProcess(); // hasFinished = true; // } catch (UploadInterruptedException e) { // hasFinished = false; // } // } // // /** // * @return true is process finished successfully // */ // protected abstract BuildFinishedStatus runProcess(); // // protected void checkIsInterrupted() throws UploadInterruptedException { // if (isInterrupted()) throw new UploadInterruptedException(); // } // // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/UploadInterruptedException.java // public class UploadInterruptedException extends RuntimeException { // // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/DeployerAgentUtils.java // public static void logBuildProblem(BuildProgressLogger logger, String message) { // logger.logBuildProblem(BuildProblemData // .createBuildProblem(String.valueOf(message.hashCode()), // DeployerRunnerConstants.BUILD_PROBLEM_TYPE, // "Deployment problem: " + message)); // }
import com.intellij.openapi.diagnostic.Logger; import jetbrains.buildServer.agent.BuildFinishedStatus; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.deployer.agent.SyncBuildProcessAdapter; import jetbrains.buildServer.deployer.agent.UploadInterruptedException; import jetbrains.buildServer.deployer.common.FTPRunnerConstants; import jetbrains.buildServer.util.StringUtil; import jetbrains.buildServer.util.WaitFor; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPSClient; import org.apache.commons.net.util.TrustManagerUtils; import org.jetbrains.annotations.NotNull; import javax.net.ssl.SSLException; import java.io.IOException; import java.net.SocketException; import java.net.URL; import java.net.URLDecoder; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import static jetbrains.buildServer.deployer.agent.DeployerAgentUtils.logBuildProblem;
final String host = targetUrl.getHost(); final int port = targetUrl.getPort(); final String encodedPath = targetUrl.getPath(); final String path; if (encodedPath.length() > 0) { path = URLDecoder.decode(encodedPath.substring(1), "UTF-8"); } else { path = ""; } final FTPClient client = createClient(); clientToDisconnect = client; if (port > 0) { client.connect(host, port); } else { client.connect(host); } client.addProtocolCommandListener(new BuildLogCommandListener(myLogger)); if (myIsActive) { client.enterLocalActiveMode(); } else { client.enterLocalPassiveMode(); } final boolean loginSuccessful = client.login(myUsername, myPassword); if (!loginSuccessful) {
// Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/SyncBuildProcessAdapter.java // public abstract class SyncBuildProcessAdapter extends BuildProcessAdapter { // protected final BuildProgressLogger myLogger; // private volatile boolean hasFinished; // private volatile BuildFinishedStatus statusCode; // private volatile boolean isInterrupted; // // // public SyncBuildProcessAdapter(@NotNull final BuildProgressLogger logger) { // myLogger = logger; // hasFinished = false; // statusCode = null; // } // // // @Override // public void interrupt() { // isInterrupted = true; // } // // @Override // public boolean isInterrupted() { // return isInterrupted; // } // // @Override // public boolean isFinished() { // return hasFinished; // } // // @NotNull // @Override // public BuildFinishedStatus waitFor() throws RunBuildException { // while (!isInterrupted() && !hasFinished) { // try { // Thread.sleep(1000); // } catch (InterruptedException e) { // throw new RunBuildException(e); // } // } // return hasFinished ? statusCode : BuildFinishedStatus.INTERRUPTED; // } // // @Override // public void start() throws RunBuildException { // try { // statusCode = runProcess(); // hasFinished = true; // } catch (UploadInterruptedException e) { // hasFinished = false; // } // } // // /** // * @return true is process finished successfully // */ // protected abstract BuildFinishedStatus runProcess(); // // protected void checkIsInterrupted() throws UploadInterruptedException { // if (isInterrupted()) throw new UploadInterruptedException(); // } // // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/UploadInterruptedException.java // public class UploadInterruptedException extends RuntimeException { // // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/DeployerAgentUtils.java // public static void logBuildProblem(BuildProgressLogger logger, String message) { // logger.logBuildProblem(BuildProblemData // .createBuildProblem(String.valueOf(message.hashCode()), // DeployerRunnerConstants.BUILD_PROBLEM_TYPE, // "Deployment problem: " + message)); // } // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ftp/FtpBuildProcessAdapter.java import com.intellij.openapi.diagnostic.Logger; import jetbrains.buildServer.agent.BuildFinishedStatus; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.deployer.agent.SyncBuildProcessAdapter; import jetbrains.buildServer.deployer.agent.UploadInterruptedException; import jetbrains.buildServer.deployer.common.FTPRunnerConstants; import jetbrains.buildServer.util.StringUtil; import jetbrains.buildServer.util.WaitFor; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPSClient; import org.apache.commons.net.util.TrustManagerUtils; import org.jetbrains.annotations.NotNull; import javax.net.ssl.SSLException; import java.io.IOException; import java.net.SocketException; import java.net.URL; import java.net.URLDecoder; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import static jetbrains.buildServer.deployer.agent.DeployerAgentUtils.logBuildProblem; final String host = targetUrl.getHost(); final int port = targetUrl.getPort(); final String encodedPath = targetUrl.getPath(); final String path; if (encodedPath.length() > 0) { path = URLDecoder.decode(encodedPath.substring(1), "UTF-8"); } else { path = ""; } final FTPClient client = createClient(); clientToDisconnect = client; if (port > 0) { client.connect(host, port); } else { client.connect(host); } client.addProtocolCommandListener(new BuildLogCommandListener(myLogger)); if (myIsActive) { client.enterLocalActiveMode(); } else { client.enterLocalPassiveMode(); } final boolean loginSuccessful = client.login(myUsername, myPassword); if (!loginSuccessful) {
logBuildProblem(myLogger, "Failed to login. Reply was: " + client.getReplyString());
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ftp/FtpBuildProcessAdapter.java
// Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/SyncBuildProcessAdapter.java // public abstract class SyncBuildProcessAdapter extends BuildProcessAdapter { // protected final BuildProgressLogger myLogger; // private volatile boolean hasFinished; // private volatile BuildFinishedStatus statusCode; // private volatile boolean isInterrupted; // // // public SyncBuildProcessAdapter(@NotNull final BuildProgressLogger logger) { // myLogger = logger; // hasFinished = false; // statusCode = null; // } // // // @Override // public void interrupt() { // isInterrupted = true; // } // // @Override // public boolean isInterrupted() { // return isInterrupted; // } // // @Override // public boolean isFinished() { // return hasFinished; // } // // @NotNull // @Override // public BuildFinishedStatus waitFor() throws RunBuildException { // while (!isInterrupted() && !hasFinished) { // try { // Thread.sleep(1000); // } catch (InterruptedException e) { // throw new RunBuildException(e); // } // } // return hasFinished ? statusCode : BuildFinishedStatus.INTERRUPTED; // } // // @Override // public void start() throws RunBuildException { // try { // statusCode = runProcess(); // hasFinished = true; // } catch (UploadInterruptedException e) { // hasFinished = false; // } // } // // /** // * @return true is process finished successfully // */ // protected abstract BuildFinishedStatus runProcess(); // // protected void checkIsInterrupted() throws UploadInterruptedException { // if (isInterrupted()) throw new UploadInterruptedException(); // } // // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/UploadInterruptedException.java // public class UploadInterruptedException extends RuntimeException { // // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/DeployerAgentUtils.java // public static void logBuildProblem(BuildProgressLogger logger, String message) { // logger.logBuildProblem(BuildProblemData // .createBuildProblem(String.valueOf(message.hashCode()), // DeployerRunnerConstants.BUILD_PROBLEM_TYPE, // "Deployment problem: " + message)); // }
import com.intellij.openapi.diagnostic.Logger; import jetbrains.buildServer.agent.BuildFinishedStatus; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.deployer.agent.SyncBuildProcessAdapter; import jetbrains.buildServer.deployer.agent.UploadInterruptedException; import jetbrains.buildServer.deployer.common.FTPRunnerConstants; import jetbrains.buildServer.util.StringUtil; import jetbrains.buildServer.util.WaitFor; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPSClient; import org.apache.commons.net.util.TrustManagerUtils; import org.jetbrains.annotations.NotNull; import javax.net.ssl.SSLException; import java.io.IOException; import java.net.SocketException; import java.net.URL; import java.net.URLDecoder; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import static jetbrains.buildServer.deployer.agent.DeployerAgentUtils.logBuildProblem;
new WaitFor(Long.MAX_VALUE, 1000) { @Override protected boolean condition() { if (uploadThread.getState() == Thread.State.TERMINATED) { return true; } try { if (isInterrupted()) { client.abort(); uploadThread.join(); return true; } } catch (Exception e) { throw new RuntimeException(e); } return false; } }; if (uploadThread.getState() != Thread.State.TERMINATED) { LOG.warn("Ftp upload thread did not reach termination state after wait operation, trying to join"); try { uploadThread.join(); } catch (InterruptedException e) { LOG.warnAndDebugDetails("Interrupted while waiting for FTP upload thread to join.", e); } LOG.warn("thread joined."); } return processResult.get();
// Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/SyncBuildProcessAdapter.java // public abstract class SyncBuildProcessAdapter extends BuildProcessAdapter { // protected final BuildProgressLogger myLogger; // private volatile boolean hasFinished; // private volatile BuildFinishedStatus statusCode; // private volatile boolean isInterrupted; // // // public SyncBuildProcessAdapter(@NotNull final BuildProgressLogger logger) { // myLogger = logger; // hasFinished = false; // statusCode = null; // } // // // @Override // public void interrupt() { // isInterrupted = true; // } // // @Override // public boolean isInterrupted() { // return isInterrupted; // } // // @Override // public boolean isFinished() { // return hasFinished; // } // // @NotNull // @Override // public BuildFinishedStatus waitFor() throws RunBuildException { // while (!isInterrupted() && !hasFinished) { // try { // Thread.sleep(1000); // } catch (InterruptedException e) { // throw new RunBuildException(e); // } // } // return hasFinished ? statusCode : BuildFinishedStatus.INTERRUPTED; // } // // @Override // public void start() throws RunBuildException { // try { // statusCode = runProcess(); // hasFinished = true; // } catch (UploadInterruptedException e) { // hasFinished = false; // } // } // // /** // * @return true is process finished successfully // */ // protected abstract BuildFinishedStatus runProcess(); // // protected void checkIsInterrupted() throws UploadInterruptedException { // if (isInterrupted()) throw new UploadInterruptedException(); // } // // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/UploadInterruptedException.java // public class UploadInterruptedException extends RuntimeException { // // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // } // // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/DeployerAgentUtils.java // public static void logBuildProblem(BuildProgressLogger logger, String message) { // logger.logBuildProblem(BuildProblemData // .createBuildProblem(String.valueOf(message.hashCode()), // DeployerRunnerConstants.BUILD_PROBLEM_TYPE, // "Deployment problem: " + message)); // } // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ftp/FtpBuildProcessAdapter.java import com.intellij.openapi.diagnostic.Logger; import jetbrains.buildServer.agent.BuildFinishedStatus; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.deployer.agent.SyncBuildProcessAdapter; import jetbrains.buildServer.deployer.agent.UploadInterruptedException; import jetbrains.buildServer.deployer.common.FTPRunnerConstants; import jetbrains.buildServer.util.StringUtil; import jetbrains.buildServer.util.WaitFor; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPSClient; import org.apache.commons.net.util.TrustManagerUtils; import org.jetbrains.annotations.NotNull; import javax.net.ssl.SSLException; import java.io.IOException; import java.net.SocketException; import java.net.URL; import java.net.URLDecoder; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import static jetbrains.buildServer.deployer.agent.DeployerAgentUtils.logBuildProblem; new WaitFor(Long.MAX_VALUE, 1000) { @Override protected boolean condition() { if (uploadThread.getState() == Thread.State.TERMINATED) { return true; } try { if (isInterrupted()) { client.abort(); uploadThread.join(); return true; } } catch (Exception e) { throw new RuntimeException(e); } return false; } }; if (uploadThread.getState() != Thread.State.TERMINATED) { LOG.warn("Ftp upload thread did not reach termination state after wait operation, trying to join"); try { uploadThread.join(); } catch (InterruptedException e) { LOG.warnAndDebugDetails("Interrupted while waiting for FTP upload thread to join.", e); } LOG.warn("thread joined."); } return processResult.get();
} catch (UploadInterruptedException e) {
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ftp/FtpDeployerRunnerInfo.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // }
import jetbrains.buildServer.agent.AgentBuildRunnerInfo; import jetbrains.buildServer.agent.BuildAgentConfiguration; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import org.jetbrains.annotations.NotNull;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.ftp; class FtpDeployerRunnerInfo implements AgentBuildRunnerInfo { @NotNull @Override public String getType() {
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ftp/FtpDeployerRunnerInfo.java import jetbrains.buildServer.agent.AgentBuildRunnerInfo; import jetbrains.buildServer.agent.BuildAgentConfiguration; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import org.jetbrains.annotations.NotNull; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.ftp; class FtpDeployerRunnerInfo implements AgentBuildRunnerInfo { @NotNull @Override public String getType() {
return DeployerRunnerConstants.FTP_RUN_TYPE;
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/BaseDeployerTest.java
// Path: deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/util/DeployTestUtils.java // public class DeployTestUtils { // public static void runProcess(final BuildProcess process, final int timeout) throws RunBuildException { // process.start(); // new WaitFor(timeout) { // @Override // protected boolean condition() { // return process.isFinished(); // } // }; // assertThat(process.isFinished()).describedAs("Failed to finish test in time").isTrue(); // assertThat(process.waitFor()).isEqualTo(BuildFinishedStatus.FINISHED_SUCCESS); // } // // public static ArtifactsCollection buildArtifactsCollection(final TempFilesFactory tempFiles, String... destinationDirs) throws IOException { // // final Map<File, String> filePathMap = new HashMap<File, String>(); // String dirTo = "dirTo"; // for (String destinationDir : destinationDirs) { // dirTo = destinationDir; // final File content = tempFiles.createTempFile(100); // filePathMap.put(content, destinationDir); // } // return new ArtifactsCollection("dirFrom/**", dirTo, filePathMap); // } // // public static void assertCollectionsTransferred(File remoteBase, List<ArtifactsCollection> artifactsCollections) throws IOException { // // for (ArtifactsCollection artifactsCollection : artifactsCollections) { // for (Map.Entry<File, String> fileStringEntry : artifactsCollection.getFilePathMap().entrySet()) { // final File source = fileStringEntry.getKey(); // final String relativePath = fileStringEntry.getValue(); // final String targetPath = relativePath + (StringUtil.isNotEmpty(relativePath) ? File.separator : "") + source.getName(); // final File target; // if (new File(targetPath).isAbsolute()) { // target = new File(targetPath); // } else { // target = new File(remoteBase, targetPath); // } // assertTrue(target.exists(), "Destination file [" + targetPath + "] does not exist"); // assertEquals(FileUtil.readText(target), FileUtil.readText(source), "wrong content"); // } // } // } // // public interface TempFilesFactory { // File createTempFile(int size) throws IOException; // } // }
import jetbrains.buildServer.BaseTestCase; import jetbrains.buildServer.deployer.agent.util.DeployTestUtils; import java.io.File; import java.io.IOException;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent; /** * Created by Nikita.Skvortsov * date: 08.07.2014. */ public class BaseDeployerTest extends BaseTestCase { protected static final int DEPLOYER_DEFAULT_PORT = 55369; protected File getTestResource(String fileName) { final String pathInBuildAgentModule = "src/test/resources/" + fileName; File file = new File(pathInBuildAgentModule); if (!file.exists()) { file = new File("deploy-runner-agent/" + pathInBuildAgentModule); } return file; }
// Path: deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/util/DeployTestUtils.java // public class DeployTestUtils { // public static void runProcess(final BuildProcess process, final int timeout) throws RunBuildException { // process.start(); // new WaitFor(timeout) { // @Override // protected boolean condition() { // return process.isFinished(); // } // }; // assertThat(process.isFinished()).describedAs("Failed to finish test in time").isTrue(); // assertThat(process.waitFor()).isEqualTo(BuildFinishedStatus.FINISHED_SUCCESS); // } // // public static ArtifactsCollection buildArtifactsCollection(final TempFilesFactory tempFiles, String... destinationDirs) throws IOException { // // final Map<File, String> filePathMap = new HashMap<File, String>(); // String dirTo = "dirTo"; // for (String destinationDir : destinationDirs) { // dirTo = destinationDir; // final File content = tempFiles.createTempFile(100); // filePathMap.put(content, destinationDir); // } // return new ArtifactsCollection("dirFrom/**", dirTo, filePathMap); // } // // public static void assertCollectionsTransferred(File remoteBase, List<ArtifactsCollection> artifactsCollections) throws IOException { // // for (ArtifactsCollection artifactsCollection : artifactsCollections) { // for (Map.Entry<File, String> fileStringEntry : artifactsCollection.getFilePathMap().entrySet()) { // final File source = fileStringEntry.getKey(); // final String relativePath = fileStringEntry.getValue(); // final String targetPath = relativePath + (StringUtil.isNotEmpty(relativePath) ? File.separator : "") + source.getName(); // final File target; // if (new File(targetPath).isAbsolute()) { // target = new File(targetPath); // } else { // target = new File(remoteBase, targetPath); // } // assertTrue(target.exists(), "Destination file [" + targetPath + "] does not exist"); // assertEquals(FileUtil.readText(target), FileUtil.readText(source), "wrong content"); // } // } // } // // public interface TempFilesFactory { // File createTempFile(int size) throws IOException; // } // } // Path: deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/BaseDeployerTest.java import jetbrains.buildServer.BaseTestCase; import jetbrains.buildServer.deployer.agent.util.DeployTestUtils; import java.io.File; import java.io.IOException; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent; /** * Created by Nikita.Skvortsov * date: 08.07.2014. */ public class BaseDeployerTest extends BaseTestCase { protected static final int DEPLOYER_DEFAULT_PORT = 55369; protected File getTestResource(String fileName) { final String pathInBuildAgentModule = "src/test/resources/" + fileName; File file = new File(pathInBuildAgentModule); if (!file.exists()) { file = new File("deploy-runner-agent/" + pathInBuildAgentModule); } return file; }
protected DeployTestUtils.TempFilesFactory createTempFilesFactory() {
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/cargo/CargoDeployerRunner.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // }
import jetbrains.buildServer.RunBuildException; import jetbrains.buildServer.agent.*; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import org.jetbrains.annotations.NotNull;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.cargo; public class CargoDeployerRunner implements AgentBuildRunner { @NotNull @Override public BuildProcess createBuildProcess(@NotNull AgentRunningBuild runningBuild, @NotNull final BuildRunnerContext context) throws RunBuildException {
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/cargo/CargoDeployerRunner.java import jetbrains.buildServer.RunBuildException; import jetbrains.buildServer.agent.*; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import org.jetbrains.annotations.NotNull; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.cargo; public class CargoDeployerRunner implements AgentBuildRunner { @NotNull @Override public BuildProcess createBuildProcess(@NotNull AgentRunningBuild runningBuild, @NotNull final BuildRunnerContext context) throws RunBuildException {
final String username = context.getRunnerParameters().get(DeployerRunnerConstants.PARAM_USERNAME);
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ftp/FtpTimeout.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // }
import com.intellij.openapi.diagnostic.Logger; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.deployer.common.FTPRunnerConstants;
package jetbrains.buildServer.deployer.agent.ftp; public class FtpTimeout { private static final Logger LOG = Logger.getInstance(FtpTimeout.class.getName()); private static final int DEFAULT_FTP_CONNECT_TIMEOUT = 30 * 1000 * 60; // 30 Min private int connectTimeout = -1; private int dataTimeout = -1; private int socketTimeout = -1; private int controlKeepAliveTimeout = -1; public static FtpTimeout parseTimeout(BuildRunnerContext context) { FtpTimeout fct = new FtpTimeout();
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java // public class FTPRunnerConstants { // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod"; // public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod"; // public static final String TRANSFER_MODE_AUTO = "AUTO"; // public static final String TRANSFER_MODE_BINARY = "BINARY"; // public static final String TRANSFER_MODE_ASCII = "ASCII"; // public static final String AUTH_METHOD_USER_PWD = "USER_PWD"; // public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS"; // public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode"; // public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection"; // public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode"; // public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout"; // public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds"; // } // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ftp/FtpTimeout.java import com.intellij.openapi.diagnostic.Logger; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.deployer.common.FTPRunnerConstants; package jetbrains.buildServer.deployer.agent.ftp; public class FtpTimeout { private static final Logger LOG = Logger.getInstance(FtpTimeout.class.getName()); private static final int DEFAULT_FTP_CONNECT_TIMEOUT = 30 * 1000 * 60; // 30 Min private int connectTimeout = -1; private int dataTimeout = -1; private int socketTimeout = -1; private int controlKeepAliveTimeout = -1; public static FtpTimeout parseTimeout(BuildRunnerContext context) { FtpTimeout fct = new FtpTimeout();
String timeout = context.getBuild().getSharedConfigParameters().get(FTPRunnerConstants.PARAM_FTP_CONNECT_TIMEOUT);
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ftp/InterruptibleUploadProcess.java
// Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/DeployerAgentUtils.java // public static void logBuildProblem(BuildProgressLogger logger, String message) { // logger.logBuildProblem(BuildProblemData // .createBuildProblem(String.valueOf(message.hashCode()), // DeployerRunnerConstants.BUILD_PROBLEM_TYPE, // "Deployment problem: " + message)); // }
import com.intellij.openapi.diagnostic.Logger; import jetbrains.buildServer.agent.BuildFinishedStatus; import jetbrains.buildServer.agent.BuildProgressLogger; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.util.StringUtil; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.StringTokenizer; import java.util.concurrent.atomic.AtomicReference; import static jetbrains.buildServer.deployer.agent.DeployerAgentUtils.logBuildProblem; import static jetbrains.buildServer.util.FileUtil.getExtension;
InputStream inputStream = null; try { if (myIsAutoType) { checkResult(myClient.setFileType(detectType(source.getName()))); } inputStream = new FileInputStream(source); checkResult(myClient.storeFile(source.getName(), inputStream)); } finally { if (inputStream != null) { inputStream.close(); } } checkResult(myClient.changeWorkingDirectory(remoteRoot)); LOG.debug("done transferring [" + source.getAbsolutePath() + "]"); count++; if (count < BY_FILE_LOGGING_THRESHOLD) { myLogger.message("Uploaded [" + source.getPath() + "] (" + StringUtil.formatFileSize(source) + ")"); } else if (count == BY_FILE_LOGGING_THRESHOLD) { myLogger.message("< and continued >"); } if (checkIsInterrupted()) throw new FailureDetectedException("Process has been interrupted."); } myLogger.message("Uploaded [" + count + "] files for [" + artifactsCollection.getSourcePath() + "] pattern"); } myFinishStatus.set(BuildFinishedStatus.FINISHED_SUCCESS); } catch (FailureDetectedException | IOException t) { if (myRetryCount == 1 && myClient.getReplyCode() == FTP_REPLY_CODE_DATA_CONNECTION_MUST_BE_ENCRYPTED) { throw new RetryWithPrivateSettingsException(); }
// Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/DeployerAgentUtils.java // public static void logBuildProblem(BuildProgressLogger logger, String message) { // logger.logBuildProblem(BuildProblemData // .createBuildProblem(String.valueOf(message.hashCode()), // DeployerRunnerConstants.BUILD_PROBLEM_TYPE, // "Deployment problem: " + message)); // } // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/ftp/InterruptibleUploadProcess.java import com.intellij.openapi.diagnostic.Logger; import jetbrains.buildServer.agent.BuildFinishedStatus; import jetbrains.buildServer.agent.BuildProgressLogger; import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection; import jetbrains.buildServer.util.StringUtil; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.StringTokenizer; import java.util.concurrent.atomic.AtomicReference; import static jetbrains.buildServer.deployer.agent.DeployerAgentUtils.logBuildProblem; import static jetbrains.buildServer.util.FileUtil.getExtension; InputStream inputStream = null; try { if (myIsAutoType) { checkResult(myClient.setFileType(detectType(source.getName()))); } inputStream = new FileInputStream(source); checkResult(myClient.storeFile(source.getName(), inputStream)); } finally { if (inputStream != null) { inputStream.close(); } } checkResult(myClient.changeWorkingDirectory(remoteRoot)); LOG.debug("done transferring [" + source.getAbsolutePath() + "]"); count++; if (count < BY_FILE_LOGGING_THRESHOLD) { myLogger.message("Uploaded [" + source.getPath() + "] (" + StringUtil.formatFileSize(source) + ")"); } else if (count == BY_FILE_LOGGING_THRESHOLD) { myLogger.message("< and continued >"); } if (checkIsInterrupted()) throw new FailureDetectedException("Process has been interrupted."); } myLogger.message("Uploaded [" + count + "] files for [" + artifactsCollection.getSourcePath() + "] pattern"); } myFinishStatus.set(BuildFinishedStatus.FINISHED_SUCCESS); } catch (FailureDetectedException | IOException t) { if (myRetryCount == 1 && myClient.getReplyCode() == FTP_REPLY_CODE_DATA_CONNECTION_MUST_BE_ENCRYPTED) { throw new RetryWithPrivateSettingsException(); }
logBuildProblem(myLogger, t.getMessage());
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/DeployerAgentUtils.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // }
import jetbrains.buildServer.BuildProblemData; import jetbrains.buildServer.agent.BuildProgressLogger; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent; public class DeployerAgentUtils { public static void logBuildProblem(BuildProgressLogger logger, String message) { logger.logBuildProblem(BuildProblemData .createBuildProblem(String.valueOf(message.hashCode()),
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // Path: deploy-runner-agent/src/main/java/jetbrains/buildServer/deployer/agent/DeployerAgentUtils.java import jetbrains.buildServer.BuildProblemData; import jetbrains.buildServer.agent.BuildProgressLogger; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent; public class DeployerAgentUtils { public static void logBuildProblem(BuildProgressLogger logger, String message) { logger.logBuildProblem(BuildProblemData .createBuildProblem(String.valueOf(message.hashCode()),
DeployerRunnerConstants.BUILD_PROBLEM_TYPE,
JetBrains/teamcity-deployer-plugin
deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/SSHDeployerRunType.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // }
import com.intellij.openapi.util.text.StringUtil; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.serverSide.RunType; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server; public class SSHDeployerRunType extends RunType { private final PluginDescriptor myDescriptor; public SSHDeployerRunType(@NotNull final RunTypeRegistry registry, @NotNull final PluginDescriptor descriptor) { myDescriptor = descriptor; registry.registerRunType(this); } @NotNull @Override public String getType() {
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // } // Path: deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/SSHDeployerRunType.java import com.intellij.openapi.util.text.StringUtil; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.serverSide.RunType; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server; public class SSHDeployerRunType extends RunType { private final PluginDescriptor myDescriptor; public SSHDeployerRunType(@NotNull final RunTypeRegistry registry, @NotNull final PluginDescriptor descriptor) { myDescriptor = descriptor; registry.registerRunType(this); } @NotNull @Override public String getType() {
return DeployerRunnerConstants.SSH_RUN_TYPE;
JetBrains/teamcity-deployer-plugin
deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/SSHDeployerRunType.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // }
import com.intellij.openapi.util.text.StringUtil; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.serverSide.RunType; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map;
@Override public String getDescription() { return "Deploys files/directories via SSH"; } @Override public PropertiesProcessor getRunnerPropertiesProcessor() { return new SSHDeployerPropertiesProcessor(); } @Override public String getEditRunnerParamsJspFilePath() { return myDescriptor.getPluginResourcesPath() + "editSSHDeployerParams.jsp"; } @Override public String getViewRunnerParamsJspFilePath() { return myDescriptor.getPluginResourcesPath() + "viewSSHDeployerParams.jsp"; } @Override public Map<String, String> getDefaultRunnerProperties() { return new HashMap<String, String>(); } @NotNull @Override public String describeParameters(@NotNull Map<String, String> parameters) { StringBuilder sb = new StringBuilder(); sb.append("Target: ").append(parameters.get(DeployerRunnerConstants.PARAM_TARGET_URL));
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // } // Path: deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/SSHDeployerRunType.java import com.intellij.openapi.util.text.StringUtil; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.serverSide.RunType; import jetbrains.buildServer.serverSide.RunTypeRegistry; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; @Override public String getDescription() { return "Deploys files/directories via SSH"; } @Override public PropertiesProcessor getRunnerPropertiesProcessor() { return new SSHDeployerPropertiesProcessor(); } @Override public String getEditRunnerParamsJspFilePath() { return myDescriptor.getPluginResourcesPath() + "editSSHDeployerParams.jsp"; } @Override public String getViewRunnerParamsJspFilePath() { return myDescriptor.getPluginResourcesPath() + "viewSSHDeployerParams.jsp"; } @Override public Map<String, String> getDefaultRunnerProperties() { return new HashMap<String, String>(); } @NotNull @Override public String describeParameters(@NotNull Map<String, String> parameters) { StringBuilder sb = new StringBuilder(); sb.append("Target: ").append(parameters.get(DeployerRunnerConstants.PARAM_TARGET_URL));
final String port = parameters.get(SSHRunnerConstants.PARAM_PORT);
JetBrains/teamcity-deployer-plugin
deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/cargo/CargoPropertiesProcessor.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/DeployerPropertiesProcessor.java // public class DeployerPropertiesProcessor implements PropertiesProcessor { // @Override // public Collection<InvalidProperty> process(Map<String, String> properties) { // Collection<InvalidProperty> result = new HashSet<InvalidProperty>(); // if (StringUtil.isEmptyOrSpaces(properties.get(DeployerRunnerConstants.PARAM_TARGET_URL))) { // result.add(new InvalidProperty(DeployerRunnerConstants.PARAM_TARGET_URL, "The target must be specified.")); // } // // if (StringUtil.isEmptyOrSpaces(properties.get(DeployerRunnerConstants.PARAM_SOURCE_PATH))) { // result.add(new InvalidProperty(DeployerRunnerConstants.PARAM_SOURCE_PATH, "Artifact to deploy must be specified")); // } // return result; // } // }
import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.server.DeployerPropertiesProcessor; import jetbrains.buildServer.serverSide.InvalidProperty; import jetbrains.buildServer.util.StringUtil; import java.util.Collection; import java.util.Map;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server.cargo; /** * Created by Nikita.Skvortsov * date: 15.07.2016. */ class CargoPropertiesProcessor extends DeployerPropertiesProcessor { @Override public Collection<InvalidProperty> process(Map<String, String> properties) { Collection<InvalidProperty> result = super.process(properties);
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/DeployerPropertiesProcessor.java // public class DeployerPropertiesProcessor implements PropertiesProcessor { // @Override // public Collection<InvalidProperty> process(Map<String, String> properties) { // Collection<InvalidProperty> result = new HashSet<InvalidProperty>(); // if (StringUtil.isEmptyOrSpaces(properties.get(DeployerRunnerConstants.PARAM_TARGET_URL))) { // result.add(new InvalidProperty(DeployerRunnerConstants.PARAM_TARGET_URL, "The target must be specified.")); // } // // if (StringUtil.isEmptyOrSpaces(properties.get(DeployerRunnerConstants.PARAM_SOURCE_PATH))) { // result.add(new InvalidProperty(DeployerRunnerConstants.PARAM_SOURCE_PATH, "Artifact to deploy must be specified")); // } // return result; // } // } // Path: deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/cargo/CargoPropertiesProcessor.java import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.server.DeployerPropertiesProcessor; import jetbrains.buildServer.serverSide.InvalidProperty; import jetbrains.buildServer.util.StringUtil; import java.util.Collection; import java.util.Map; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server.cargo; /** * Created by Nikita.Skvortsov * date: 15.07.2016. */ class CargoPropertiesProcessor extends DeployerPropertiesProcessor { @Override public Collection<InvalidProperty> process(Map<String, String> properties) { Collection<InvalidProperty> result = super.process(properties);
if (StringUtil.isEmptyOrSpaces(properties.get(DeployerRunnerConstants.PARAM_USERNAME))) {
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/ssh/SSHSessionProviderTest.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // }
import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.util.FileUtil; import org.testng.annotations.Test; import java.io.File; import static org.testng.Assert.assertTrue;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.ssh; /** * Created by Nikita.Skvortsov * date: 29.07.13. */ @Test public class SSHSessionProviderTest extends BaseSSHTest { public void testUsernamePassword() throws Exception { assertSessionIsConnected(); } public void testCustomKey() throws Exception {
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // } // Path: deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/ssh/SSHSessionProviderTest.java import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.util.FileUtil; import org.testng.annotations.Test; import java.io.File; import static org.testng.Assert.assertTrue; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.ssh; /** * Created by Nikita.Skvortsov * date: 29.07.13. */ @Test public class SSHSessionProviderTest extends BaseSSHTest { public void testUsernamePassword() throws Exception { assertSessionIsConnected(); } public void testCustomKey() throws Exception {
myRunnerParams.put(SSHRunnerConstants.PARAM_AUTH_METHOD, SSHRunnerConstants.AUTH_METHOD_CUSTOM_KEY);
JetBrains/teamcity-deployer-plugin
deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/ssh/SSHSessionProviderTest.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // }
import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.util.FileUtil; import org.testng.annotations.Test; import java.io.File; import static org.testng.Assert.assertTrue;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.ssh; /** * Created by Nikita.Skvortsov * date: 29.07.13. */ @Test public class SSHSessionProviderTest extends BaseSSHTest { public void testUsernamePassword() throws Exception { assertSessionIsConnected(); } public void testCustomKey() throws Exception { myRunnerParams.put(SSHRunnerConstants.PARAM_AUTH_METHOD, SSHRunnerConstants.AUTH_METHOD_CUSTOM_KEY); myRunnerParams.put(SSHRunnerConstants.PARAM_KEYFILE, FileUtil.getRelativePath(myWorkingDir, myPrivateKey));
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // // Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/SSHRunnerConstants.java // public class SSHRunnerConstants { // // public static final String SSH_EXEC_RUN_TYPE = "ssh-exec-runner"; // // @Deprecated // public static final String PARAM_HOST = "jetbrains.buildServer.sshexec.host"; // public static final String PARAM_PORT = "jetbrains.buildServer.sshexec.port"; // @Deprecated // public static final String PARAM_USERNAME = "jetbrains.buildServer.sshexec.username"; // @Deprecated // public static final String PARAM_PASSWORD = "jetbrains.buildServer.sshexec.password"; // public static final String PARAM_KEYFILE = "jetbrains.buildServer.sshexec.keyFile"; // public static final String PARAM_UPLOADED_KEY_ID = "jetbrains.buildServer.sshexec.key.id"; // public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.sshexec.authMethod"; // public static final String PARAM_COMMAND = "jetbrains.buildServer.sshexec.command"; // public static final String PARAM_PTY = "jetbrains.buildServer.sshexec.pty"; // // public static final String PARAM_TRANSPORT = "jetbrains.buildServer.deployer.ssh.transport"; // // public static final String TRANSPORT_SCP = "jetbrains.buildServer.deployer.ssh.transport.scp"; // public static final String TRANSPORT_SFTP = "jetbrains.buildServer.deployer.ssh.transport.sftp"; // public static final String AUTH_METHOD_DEFAULT_KEY = "DEFAULT_KEY"; // public static final String AUTH_METHOD_CUSTOM_KEY = "CUSTOM_KEY"; // public static final String AUTH_METHOD_USERNAME_PWD = "PWD"; // public static final String AUTH_METHOD_SSH_AGENT = "SSH_AGENT"; // public static final String AUTH_METHOD_UPLOADED_KEY = "UPLOADED_KEY"; // // public static final String ENABLE_SSH_AGENT_FORWARDING = "teamcity.deployer.ssh.enableAgentForwarding"; // // public String getTransportType() { // return PARAM_TRANSPORT; // } // // public Map<String, String> getTransportTypeValues() { // final Map<String, String> result = new LinkedHashMap<String, String>(); // result.put(TRANSPORT_SCP, "SCP"); // result.put(TRANSPORT_SFTP, "SFTP"); // return result; // } // // // } // Path: deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/ssh/SSHSessionProviderTest.java import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.deployer.common.SSHRunnerConstants; import jetbrains.buildServer.util.FileUtil; import org.testng.annotations.Test; import java.io.File; import static org.testng.Assert.assertTrue; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.agent.ssh; /** * Created by Nikita.Skvortsov * date: 29.07.13. */ @Test public class SSHSessionProviderTest extends BaseSSHTest { public void testUsernamePassword() throws Exception { assertSessionIsConnected(); } public void testCustomKey() throws Exception { myRunnerParams.put(SSHRunnerConstants.PARAM_AUTH_METHOD, SSHRunnerConstants.AUTH_METHOD_CUSTOM_KEY); myRunnerParams.put(SSHRunnerConstants.PARAM_KEYFILE, FileUtil.getRelativePath(myWorkingDir, myPrivateKey));
myRunnerParams.put(DeployerRunnerConstants.PARAM_PASSWORD, "passphrase");
JetBrains/teamcity-deployer-plugin
deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/DeployerPropertiesProcessor.java
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // }
import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.serverSide.InvalidProperty; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.util.StringUtil; import java.util.Collection; import java.util.HashSet; import java.util.Map;
/* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server; /** * Created by Kit * Date: 24.03.12 - 17:16 */ public class DeployerPropertiesProcessor implements PropertiesProcessor { @Override public Collection<InvalidProperty> process(Map<String, String> properties) { Collection<InvalidProperty> result = new HashSet<InvalidProperty>();
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/DeployerRunnerConstants.java // public class DeployerRunnerConstants { // public static final String SSH_RUN_TYPE = "ssh-deploy-runner"; // public static final String SMB_RUN_TYPE = "smb-deploy-runner"; // public static final String SMB2_RUN_TYPE = "smb2-deploy-runner"; // public static final String FTP_RUN_TYPE = "ftp-deploy-runner"; // public static final String TOMCAT_RUN_TYPE = "tomcat-deploy-runner"; // public static final String CARGO_RUN_TYPE = "cargo-deploy-runner"; // // // public static final String PARAM_USERNAME = "jetbrains.buildServer.deployer.username"; // public static final String PARAM_PASSWORD = "secure:jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_PLAIN_PASSWORD = "jetbrains.buildServer.deployer.password"; // @Deprecated // public static final String PARAM_DOMAIN = "jetbrains.buildServer.deployer.domain"; // public static final String PARAM_TARGET_URL = "jetbrains.buildServer.deployer.targetUrl"; // public static final String PARAM_SOURCE_PATH = "jetbrains.buildServer.deployer.sourcePath"; // public static final String PARAM_CONTAINER_CONTEXT_PATH = "jetbrains.buildServer.deployer.container.contextPath"; // public static final String PARAM_CONTAINER_TYPE = "jetbrains.buildServer.deployer.container.type"; // // public static final String BUILD_PROBLEM_TYPE = "jetbrains.buildServer.deployer"; // } // Path: deploy-runner-server/src/main/java/jetbrains/buildServer/deployer/server/DeployerPropertiesProcessor.java import jetbrains.buildServer.deployer.common.DeployerRunnerConstants; import jetbrains.buildServer.serverSide.InvalidProperty; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.util.StringUtil; import java.util.Collection; import java.util.HashSet; import java.util.Map; /* * Copyright 2000-2022 JetBrains s.r.o. * * 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 jetbrains.buildServer.deployer.server; /** * Created by Kit * Date: 24.03.12 - 17:16 */ public class DeployerPropertiesProcessor implements PropertiesProcessor { @Override public Collection<InvalidProperty> process(Map<String, String> properties) { Collection<InvalidProperty> result = new HashSet<InvalidProperty>();
if (StringUtil.isEmptyOrSpaces(properties.get(DeployerRunnerConstants.PARAM_TARGET_URL))) {
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/TemplateTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // }
import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import org.junit.Test; import java.io.IOException; import java.util.Arrays; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.IsCollectionContaining.hasItems; import static org.junit.Assert.assertNotNull;
package de.fesere.hypermedia.cj.model; public class TemplateTest extends SerializationTestBase { @Test public void testCollectionWithTemplate() { Collection result = readCollection("examples/template-collection.json"); assertThat(result.getTemplate().getData(), hasSize(4)); assertThat(result.getTemplate().getData(), hasItems(name("full-name"), name("email"), name("blog"), name("avatar"))); assertThat(result.getTemplate().getDataMap().keySet(), hasSize(4)); } @Test public void test_fill() throws IOException {
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // Path: src/test/java/de/fesere/hypermedia/cj/model/TemplateTest.java import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import org.junit.Test; import java.io.IOException; import java.util.Arrays; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.IsCollectionContaining.hasItems; import static org.junit.Assert.assertNotNull; package de.fesere.hypermedia.cj.model; public class TemplateTest extends SerializationTestBase { @Test public void testCollectionWithTemplate() { Collection result = readCollection("examples/template-collection.json"); assertThat(result.getTemplate().getData(), hasSize(4)); assertThat(result.getTemplate().getData(), hasItems(name("full-name"), name("email"), name("blog"), name("avatar"))); assertThat(result.getTemplate().getDataMap().keySet(), hasSize(4)); } @Test public void test_fill() throws IOException {
Template template = new Template(Arrays.asList(create("full-name", "", "Full Name"),
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/TemplateTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // }
import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import org.junit.Test; import java.io.IOException; import java.util.Arrays; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.IsCollectionContaining.hasItems; import static org.junit.Assert.assertNotNull;
package de.fesere.hypermedia.cj.model; public class TemplateTest extends SerializationTestBase { @Test public void testCollectionWithTemplate() { Collection result = readCollection("examples/template-collection.json"); assertThat(result.getTemplate().getData(), hasSize(4)); assertThat(result.getTemplate().getData(), hasItems(name("full-name"), name("email"), name("blog"), name("avatar"))); assertThat(result.getTemplate().getDataMap().keySet(), hasSize(4)); } @Test public void test_fill() throws IOException { Template template = new Template(Arrays.asList(create("full-name", "", "Full Name"), create("age", ""), create("pi", ""), create("admin", "")));
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // Path: src/test/java/de/fesere/hypermedia/cj/model/TemplateTest.java import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import org.junit.Test; import java.io.IOException; import java.util.Arrays; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.IsCollectionContaining.hasItems; import static org.junit.Assert.assertNotNull; package de.fesere.hypermedia.cj.model; public class TemplateTest extends SerializationTestBase { @Test public void testCollectionWithTemplate() { Collection result = readCollection("examples/template-collection.json"); assertThat(result.getTemplate().getData(), hasSize(4)); assertThat(result.getTemplate().getData(), hasItems(name("full-name"), name("email"), name("blog"), name("avatar"))); assertThat(result.getTemplate().getDataMap().keySet(), hasSize(4)); } @Test public void test_fill() throws IOException { Template template = new Template(Arrays.asList(create("full-name", "", "Full Name"), create("age", ""), create("pi", ""), create("admin", "")));
Item item = new Item(Arrays.asList(DataEntryFactory.create("full-name", "Felipe Sere"), create("age", 46), create("pi", 3.14), create("admin", false)));
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/transformer/DataEntryTransformer.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonPropertyOrder({"href", "data", "links"}) // public class Item { // private final URI href; // private final List<DataEntry> data = new ArrayList<>(); // private List<Link> links = new ArrayList<>(); // // // public Item() { // this(Collections.<DataEntry>emptyList()); // } // // public Item(List<DataEntry> data) { // this((URI) null); // if (data != null) { // this.data.addAll(data); // } // } // // public Item(URI href) { // this(href, Collections.<Link>emptyList()); // } // // @JsonCreator // public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { // this.href = href; // this.links = links; // } // // public Item(URI href, List<DataEntry> entries, List<Link> links) { // this(href, links); // this.data.addAll(entries); // } // // public URI getHref() { // return this.href; // } // // public void addData(DataEntry dataEntry) { // data.add(dataEntry); // } // // public List<DataEntry> getData() { // return new ArrayList<>(data); // } // // public List<Link> getLinks() { // return links; // } // // public String getString(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof StringDataEntry) { // return ((StringDataEntry) found).getValue(); // } // throw new PropertyNotFoundException(name, href, String.class); // } // // public boolean isNullValue(String name) { // DataEntry found = findDataEntry(name); // // return found instanceof NullDataEntry; // } // // public int getInt(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Integer.parseInt(value.toString()); // // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public double getDouble(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Double.parseDouble(value.toString()); // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public boolean getBoolean(String name) { // DataEntry entry = findDataEntry(name); // if (entry instanceof BooleanDataEntry) { // return (boolean) entry.getValue(); // } // // throw new PropertyNotFoundException(name, href, Boolean.class); // } // // private DataEntry findDataEntry(String name) { // DataEntry found = null; // for (DataEntry entry : data) { // if (entry.getName().equals(name)) { // found = entry; // break; // } // } // if (found == null) { // throw new ElementNotFoundException("Did not find property '" + name + "' in '" + href + "'"); // } // return found; // } // // public Map<String, Object> extractDataMap() { // Map<String, Object> result = new HashMap<>(); // for (DataEntry entry : data) { // result.put(entry.getName(), entry.getValue()); // } // // return result; // } // // public Object getObject(String entryName) { // DataEntry entry = findDataEntry(entryName); // // return entry.getValue(); // } // }
import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.Item; import java.util.List;
package de.fesere.hypermedia.cj.transformer; public class DataEntryTransformer<T> implements ReadTransformation<T> { private ReadTransformation<T> innerTransformer; public DataEntryTransformer(ReadTransformation<T> innerTransformer) { this.innerTransformer = innerTransformer; }
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonPropertyOrder({"href", "data", "links"}) // public class Item { // private final URI href; // private final List<DataEntry> data = new ArrayList<>(); // private List<Link> links = new ArrayList<>(); // // // public Item() { // this(Collections.<DataEntry>emptyList()); // } // // public Item(List<DataEntry> data) { // this((URI) null); // if (data != null) { // this.data.addAll(data); // } // } // // public Item(URI href) { // this(href, Collections.<Link>emptyList()); // } // // @JsonCreator // public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { // this.href = href; // this.links = links; // } // // public Item(URI href, List<DataEntry> entries, List<Link> links) { // this(href, links); // this.data.addAll(entries); // } // // public URI getHref() { // return this.href; // } // // public void addData(DataEntry dataEntry) { // data.add(dataEntry); // } // // public List<DataEntry> getData() { // return new ArrayList<>(data); // } // // public List<Link> getLinks() { // return links; // } // // public String getString(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof StringDataEntry) { // return ((StringDataEntry) found).getValue(); // } // throw new PropertyNotFoundException(name, href, String.class); // } // // public boolean isNullValue(String name) { // DataEntry found = findDataEntry(name); // // return found instanceof NullDataEntry; // } // // public int getInt(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Integer.parseInt(value.toString()); // // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public double getDouble(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Double.parseDouble(value.toString()); // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public boolean getBoolean(String name) { // DataEntry entry = findDataEntry(name); // if (entry instanceof BooleanDataEntry) { // return (boolean) entry.getValue(); // } // // throw new PropertyNotFoundException(name, href, Boolean.class); // } // // private DataEntry findDataEntry(String name) { // DataEntry found = null; // for (DataEntry entry : data) { // if (entry.getName().equals(name)) { // found = entry; // break; // } // } // if (found == null) { // throw new ElementNotFoundException("Did not find property '" + name + "' in '" + href + "'"); // } // return found; // } // // public Map<String, Object> extractDataMap() { // Map<String, Object> result = new HashMap<>(); // for (DataEntry entry : data) { // result.put(entry.getName(), entry.getValue()); // } // // return result; // } // // public Object getObject(String entryName) { // DataEntry entry = findDataEntry(entryName); // // return entry.getValue(); // } // } // Path: src/main/java/de/fesere/hypermedia/cj/transformer/DataEntryTransformer.java import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.Item; import java.util.List; package de.fesere.hypermedia.cj.transformer; public class DataEntryTransformer<T> implements ReadTransformation<T> { private ReadTransformation<T> innerTransformer; public DataEntryTransformer(ReadTransformation<T> innerTransformer) { this.innerTransformer = innerTransformer; }
public T transform(List<DataEntry> dataEntryList) {
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/transformer/DataEntryTransformer.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonPropertyOrder({"href", "data", "links"}) // public class Item { // private final URI href; // private final List<DataEntry> data = new ArrayList<>(); // private List<Link> links = new ArrayList<>(); // // // public Item() { // this(Collections.<DataEntry>emptyList()); // } // // public Item(List<DataEntry> data) { // this((URI) null); // if (data != null) { // this.data.addAll(data); // } // } // // public Item(URI href) { // this(href, Collections.<Link>emptyList()); // } // // @JsonCreator // public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { // this.href = href; // this.links = links; // } // // public Item(URI href, List<DataEntry> entries, List<Link> links) { // this(href, links); // this.data.addAll(entries); // } // // public URI getHref() { // return this.href; // } // // public void addData(DataEntry dataEntry) { // data.add(dataEntry); // } // // public List<DataEntry> getData() { // return new ArrayList<>(data); // } // // public List<Link> getLinks() { // return links; // } // // public String getString(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof StringDataEntry) { // return ((StringDataEntry) found).getValue(); // } // throw new PropertyNotFoundException(name, href, String.class); // } // // public boolean isNullValue(String name) { // DataEntry found = findDataEntry(name); // // return found instanceof NullDataEntry; // } // // public int getInt(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Integer.parseInt(value.toString()); // // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public double getDouble(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Double.parseDouble(value.toString()); // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public boolean getBoolean(String name) { // DataEntry entry = findDataEntry(name); // if (entry instanceof BooleanDataEntry) { // return (boolean) entry.getValue(); // } // // throw new PropertyNotFoundException(name, href, Boolean.class); // } // // private DataEntry findDataEntry(String name) { // DataEntry found = null; // for (DataEntry entry : data) { // if (entry.getName().equals(name)) { // found = entry; // break; // } // } // if (found == null) { // throw new ElementNotFoundException("Did not find property '" + name + "' in '" + href + "'"); // } // return found; // } // // public Map<String, Object> extractDataMap() { // Map<String, Object> result = new HashMap<>(); // for (DataEntry entry : data) { // result.put(entry.getName(), entry.getValue()); // } // // return result; // } // // public Object getObject(String entryName) { // DataEntry entry = findDataEntry(entryName); // // return entry.getValue(); // } // }
import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.Item; import java.util.List;
package de.fesere.hypermedia.cj.transformer; public class DataEntryTransformer<T> implements ReadTransformation<T> { private ReadTransformation<T> innerTransformer; public DataEntryTransformer(ReadTransformation<T> innerTransformer) { this.innerTransformer = innerTransformer; } public T transform(List<DataEntry> dataEntryList) {
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonPropertyOrder({"href", "data", "links"}) // public class Item { // private final URI href; // private final List<DataEntry> data = new ArrayList<>(); // private List<Link> links = new ArrayList<>(); // // // public Item() { // this(Collections.<DataEntry>emptyList()); // } // // public Item(List<DataEntry> data) { // this((URI) null); // if (data != null) { // this.data.addAll(data); // } // } // // public Item(URI href) { // this(href, Collections.<Link>emptyList()); // } // // @JsonCreator // public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { // this.href = href; // this.links = links; // } // // public Item(URI href, List<DataEntry> entries, List<Link> links) { // this(href, links); // this.data.addAll(entries); // } // // public URI getHref() { // return this.href; // } // // public void addData(DataEntry dataEntry) { // data.add(dataEntry); // } // // public List<DataEntry> getData() { // return new ArrayList<>(data); // } // // public List<Link> getLinks() { // return links; // } // // public String getString(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof StringDataEntry) { // return ((StringDataEntry) found).getValue(); // } // throw new PropertyNotFoundException(name, href, String.class); // } // // public boolean isNullValue(String name) { // DataEntry found = findDataEntry(name); // // return found instanceof NullDataEntry; // } // // public int getInt(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Integer.parseInt(value.toString()); // // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public double getDouble(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Double.parseDouble(value.toString()); // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public boolean getBoolean(String name) { // DataEntry entry = findDataEntry(name); // if (entry instanceof BooleanDataEntry) { // return (boolean) entry.getValue(); // } // // throw new PropertyNotFoundException(name, href, Boolean.class); // } // // private DataEntry findDataEntry(String name) { // DataEntry found = null; // for (DataEntry entry : data) { // if (entry.getName().equals(name)) { // found = entry; // break; // } // } // if (found == null) { // throw new ElementNotFoundException("Did not find property '" + name + "' in '" + href + "'"); // } // return found; // } // // public Map<String, Object> extractDataMap() { // Map<String, Object> result = new HashMap<>(); // for (DataEntry entry : data) { // result.put(entry.getName(), entry.getValue()); // } // // return result; // } // // public Object getObject(String entryName) { // DataEntry entry = findDataEntry(entryName); // // return entry.getValue(); // } // } // Path: src/main/java/de/fesere/hypermedia/cj/transformer/DataEntryTransformer.java import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.Item; import java.util.List; package de.fesere.hypermedia.cj.transformer; public class DataEntryTransformer<T> implements ReadTransformation<T> { private ReadTransformation<T> innerTransformer; public DataEntryTransformer(ReadTransformation<T> innerTransformer) { this.innerTransformer = innerTransformer; } public T transform(List<DataEntry> dataEntryList) {
Item item = new Item(dataEntryList);
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/QueryTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // }
import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import org.junit.Test; import java.net.URI; import java.util.Arrays; import java.util.LinkedList; import java.util.List; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.createEmpty; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.Is.is;
@Test public void testBuildURI_singleElementInQueryIsSetToString() { Query theQuery = createBaseQueryWith3Entries(); theQuery.set("foo", "a"); URI uri = theQuery.buildURI(); assertThat(uri.toString(), is(BASE_URI+"?foo=a")); } @Test public void testBuildURI_singleElementInQueryIsSetToInt() { Query theQuery = createBaseQueryWith3Entries(); theQuery.set("foo", 12); URI uri = theQuery.buildURI(); assertThat(uri.toString(), is(BASE_URI+"?foo=12")); } @Test public void testBuildURI_singleElementInQueryIsSetToBoolean() { Query theQuery = createBaseQueryWith3Entries(); theQuery.set("foo", true); URI uri = theQuery.buildURI(); assertThat(uri.toString(), is(BASE_URI+"?foo=true")); }
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // Path: src/test/java/de/fesere/hypermedia/cj/model/QueryTest.java import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import org.junit.Test; import java.net.URI; import java.util.Arrays; import java.util.LinkedList; import java.util.List; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.createEmpty; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.Is.is; @Test public void testBuildURI_singleElementInQueryIsSetToString() { Query theQuery = createBaseQueryWith3Entries(); theQuery.set("foo", "a"); URI uri = theQuery.buildURI(); assertThat(uri.toString(), is(BASE_URI+"?foo=a")); } @Test public void testBuildURI_singleElementInQueryIsSetToInt() { Query theQuery = createBaseQueryWith3Entries(); theQuery.set("foo", 12); URI uri = theQuery.buildURI(); assertThat(uri.toString(), is(BASE_URI+"?foo=12")); } @Test public void testBuildURI_singleElementInQueryIsSetToBoolean() { Query theQuery = createBaseQueryWith3Entries(); theQuery.set("foo", true); URI uri = theQuery.buildURI(); assertThat(uri.toString(), is(BASE_URI+"?foo=true")); }
@Test(expected = ElementNotFoundException.class)
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/QueryTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // }
import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import org.junit.Test; import java.net.URI; import java.util.Arrays; import java.util.LinkedList; import java.util.List; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.createEmpty; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.Is.is;
@Test public void testBuildURI_singleElementInQueryIsSetToInt() { Query theQuery = createBaseQueryWith3Entries(); theQuery.set("foo", 12); URI uri = theQuery.buildURI(); assertThat(uri.toString(), is(BASE_URI+"?foo=12")); } @Test public void testBuildURI_singleElementInQueryIsSetToBoolean() { Query theQuery = createBaseQueryWith3Entries(); theQuery.set("foo", true); URI uri = theQuery.buildURI(); assertThat(uri.toString(), is(BASE_URI+"?foo=true")); } @Test(expected = ElementNotFoundException.class) public void testBuildURI_settingNonExistingElementThrowsException() { Query theQuery = createBaseQueryWith3Entries(); theQuery.set("doesNotExist", "a"); } @Test public void testBuildUri_settingBooleanAndNumber_success() {
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // Path: src/test/java/de/fesere/hypermedia/cj/model/QueryTest.java import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import org.junit.Test; import java.net.URI; import java.util.Arrays; import java.util.LinkedList; import java.util.List; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.createEmpty; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.Is.is; @Test public void testBuildURI_singleElementInQueryIsSetToInt() { Query theQuery = createBaseQueryWith3Entries(); theQuery.set("foo", 12); URI uri = theQuery.buildURI(); assertThat(uri.toString(), is(BASE_URI+"?foo=12")); } @Test public void testBuildURI_singleElementInQueryIsSetToBoolean() { Query theQuery = createBaseQueryWith3Entries(); theQuery.set("foo", true); URI uri = theQuery.buildURI(); assertThat(uri.toString(), is(BASE_URI+"?foo=true")); } @Test(expected = ElementNotFoundException.class) public void testBuildURI_settingNonExistingElementThrowsException() { Query theQuery = createBaseQueryWith3Entries(); theQuery.set("doesNotExist", "a"); } @Test public void testBuildUri_settingBooleanAndNumber_success() {
Query theQury = new Query(BASE_URI, "foo", null, Arrays.asList(createEmpty("admin"), createEmpty("age")));
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/IntegrationTest.java
// Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/Department.java // public class Department { // private final String nr; // private final String name; // private final URI link; // // public Department(String nr, String name, URI link) { // this.nr = nr; // this.name = name; // this.link = link; // } // // public URI getLink(){ // return link; // } // // // public String toString() { // return "Department [nr: " + nr + ", name:" + name+"]"; // } // } // // Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/EmployeeDB.java // public class EmployeeDB { // // private final CjClient httpCjClient = new CjClient(new ApacheClient()); // // private URI departmentsURI = null; // private final URI employeesURI; // // // public EmployeeDB() { // URI START = URI.create("http://employee.herokuapp.com"); // Collection rootCollection = httpCjClient.readCollection(START); // // handlePossibleErrors(rootCollection); // // departmentsURI = rootCollection.getLink("departments").getHref(); // employeesURI = rootCollection.getLink("employees").getHref(); // } // // void handlePossibleErrors(Collection collection) { // if(collection.hasError()) { // throw new RuntimeException(collection.getError().getMessage()); // } // } // // public void addNewEmployee(Employee employee) { // Collection employees = httpCjClient.readCollection(employeesURI); // // Template template = employees.getTemplate(); // template.fill(new EmployeeTransformer().transform(employee)); // // httpCjClient.addItem(employees.getHref(), template); // } // // public List<Employee> getEmployeesOfDepartment(String departmentName) { // Collection departments = httpCjClient.readCollection(departmentsURI); // // Iterator<Collection> collectionIterator = new CollectionIterator(departments, httpCjClient); // // List<Item> items = new LinkedList<>(); // while(collectionIterator.hasNext()) { // Collection subset = collectionIterator.next(); // items.addAll(subset.getItems()); // } // // // Item foundItem = null; // for(Item item : items) { // if(item.getString("dept_name").equalsIgnoreCase(departmentName)) { // foundItem=item; // } // } // // if(foundItem == null) { // return Collections.emptyList(); // } // // Collection department = httpCjClient.readCollection(foundItem.getHref()); // // Collection employees = httpCjClient.readCollection(department.getLink("employees").getHref()); // // Iterator<Collection> employeeIter = new CollectionIterator(employees, httpCjClient); // List<Item> employeeItems = new LinkedList<>(); // while(employeeIter.hasNext()) { // employeeItems.addAll(employeeIter.next().getItems()); // System.out.println(employeeItems.size()); // } // // Collection finalEmployees = new Collection(employees.getHref(), employeeItems, employees.getQueries(), employees.getLinks(), employees.getTemplate()); // // return finalEmployees.transform(new EmployeeTransformer()); // } // // public List<Department> getAllDepartments() { // Collection departments = httpCjClient.readCollection(departmentsURI); // // Iterator<Collection> iterator = new CollectionIterator(departments, httpCjClient); // List<Item> items = new LinkedList<>(); // while(iterator.hasNext()) { // System.out.println("itearion!"); // items.addAll(iterator.next().getItems()); // } // // handlePossibleErrors(departments); // // Collection finalCollection = new Collection(departments.getHref(), items, departments.getQueries(), departments.getLinks(), departments.getTemplate()); // // return finalCollection.transform(new DepratmentTransformer()); // } // // public List<Employee> getAllEmployees() { // Collection employees = httpCjClient.readCollection(employeesURI); // // handlePossibleErrors(employees); // // return employees.transform(new EmployeeTransformer()); // } // // public List<Employee> findEmployeeByName(String name) { // Collection employees = httpCjClient.readCollection(employeesURI); // Query searchQuery = employees.getQuery("search"); // // Query filledQuery = searchQuery.set("name", name); // // return httpCjClient.follow(filledQuery).transform(new EmployeeTransformer()); // } // // private class CollectionIterator implements Iterator<Collection> { // // private Collection context; // private final CjClient cjClient; // // public CollectionIterator(Collection context, CjClient cjClient) { // this.context = context; // this.cjClient = cjClient; // } // // @Override // public boolean hasNext() { // return context != null && context.getLink("next") != null; // } // // @Override // public Collection next() { // // URI nextUri = context.getLink("next").getHref(); // // Collection next = cjClient.readCollection(nextUri); // context = next; // // return next; // } // // @Override // public void remove() { // } // } // }
import de.fesere.hypermedia.cj.example.employeeDB.Department; import de.fesere.hypermedia.cj.example.employeeDB.EmployeeDB; import org.junit.Ignore; import org.junit.Test; import java.util.List;
package de.fesere.hypermedia.cj.model; public class IntegrationTest { @Ignore("Runs against a real API") @Test public void test() {
// Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/Department.java // public class Department { // private final String nr; // private final String name; // private final URI link; // // public Department(String nr, String name, URI link) { // this.nr = nr; // this.name = name; // this.link = link; // } // // public URI getLink(){ // return link; // } // // // public String toString() { // return "Department [nr: " + nr + ", name:" + name+"]"; // } // } // // Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/EmployeeDB.java // public class EmployeeDB { // // private final CjClient httpCjClient = new CjClient(new ApacheClient()); // // private URI departmentsURI = null; // private final URI employeesURI; // // // public EmployeeDB() { // URI START = URI.create("http://employee.herokuapp.com"); // Collection rootCollection = httpCjClient.readCollection(START); // // handlePossibleErrors(rootCollection); // // departmentsURI = rootCollection.getLink("departments").getHref(); // employeesURI = rootCollection.getLink("employees").getHref(); // } // // void handlePossibleErrors(Collection collection) { // if(collection.hasError()) { // throw new RuntimeException(collection.getError().getMessage()); // } // } // // public void addNewEmployee(Employee employee) { // Collection employees = httpCjClient.readCollection(employeesURI); // // Template template = employees.getTemplate(); // template.fill(new EmployeeTransformer().transform(employee)); // // httpCjClient.addItem(employees.getHref(), template); // } // // public List<Employee> getEmployeesOfDepartment(String departmentName) { // Collection departments = httpCjClient.readCollection(departmentsURI); // // Iterator<Collection> collectionIterator = new CollectionIterator(departments, httpCjClient); // // List<Item> items = new LinkedList<>(); // while(collectionIterator.hasNext()) { // Collection subset = collectionIterator.next(); // items.addAll(subset.getItems()); // } // // // Item foundItem = null; // for(Item item : items) { // if(item.getString("dept_name").equalsIgnoreCase(departmentName)) { // foundItem=item; // } // } // // if(foundItem == null) { // return Collections.emptyList(); // } // // Collection department = httpCjClient.readCollection(foundItem.getHref()); // // Collection employees = httpCjClient.readCollection(department.getLink("employees").getHref()); // // Iterator<Collection> employeeIter = new CollectionIterator(employees, httpCjClient); // List<Item> employeeItems = new LinkedList<>(); // while(employeeIter.hasNext()) { // employeeItems.addAll(employeeIter.next().getItems()); // System.out.println(employeeItems.size()); // } // // Collection finalEmployees = new Collection(employees.getHref(), employeeItems, employees.getQueries(), employees.getLinks(), employees.getTemplate()); // // return finalEmployees.transform(new EmployeeTransformer()); // } // // public List<Department> getAllDepartments() { // Collection departments = httpCjClient.readCollection(departmentsURI); // // Iterator<Collection> iterator = new CollectionIterator(departments, httpCjClient); // List<Item> items = new LinkedList<>(); // while(iterator.hasNext()) { // System.out.println("itearion!"); // items.addAll(iterator.next().getItems()); // } // // handlePossibleErrors(departments); // // Collection finalCollection = new Collection(departments.getHref(), items, departments.getQueries(), departments.getLinks(), departments.getTemplate()); // // return finalCollection.transform(new DepratmentTransformer()); // } // // public List<Employee> getAllEmployees() { // Collection employees = httpCjClient.readCollection(employeesURI); // // handlePossibleErrors(employees); // // return employees.transform(new EmployeeTransformer()); // } // // public List<Employee> findEmployeeByName(String name) { // Collection employees = httpCjClient.readCollection(employeesURI); // Query searchQuery = employees.getQuery("search"); // // Query filledQuery = searchQuery.set("name", name); // // return httpCjClient.follow(filledQuery).transform(new EmployeeTransformer()); // } // // private class CollectionIterator implements Iterator<Collection> { // // private Collection context; // private final CjClient cjClient; // // public CollectionIterator(Collection context, CjClient cjClient) { // this.context = context; // this.cjClient = cjClient; // } // // @Override // public boolean hasNext() { // return context != null && context.getLink("next") != null; // } // // @Override // public Collection next() { // // URI nextUri = context.getLink("next").getHref(); // // Collection next = cjClient.readCollection(nextUri); // context = next; // // return next; // } // // @Override // public void remove() { // } // } // } // Path: src/test/java/de/fesere/hypermedia/cj/model/IntegrationTest.java import de.fesere.hypermedia.cj.example.employeeDB.Department; import de.fesere.hypermedia.cj.example.employeeDB.EmployeeDB; import org.junit.Ignore; import org.junit.Test; import java.util.List; package de.fesere.hypermedia.cj.model; public class IntegrationTest { @Ignore("Runs against a real API") @Test public void test() {
EmployeeDB employeeDB = new EmployeeDB();
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/IntegrationTest.java
// Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/Department.java // public class Department { // private final String nr; // private final String name; // private final URI link; // // public Department(String nr, String name, URI link) { // this.nr = nr; // this.name = name; // this.link = link; // } // // public URI getLink(){ // return link; // } // // // public String toString() { // return "Department [nr: " + nr + ", name:" + name+"]"; // } // } // // Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/EmployeeDB.java // public class EmployeeDB { // // private final CjClient httpCjClient = new CjClient(new ApacheClient()); // // private URI departmentsURI = null; // private final URI employeesURI; // // // public EmployeeDB() { // URI START = URI.create("http://employee.herokuapp.com"); // Collection rootCollection = httpCjClient.readCollection(START); // // handlePossibleErrors(rootCollection); // // departmentsURI = rootCollection.getLink("departments").getHref(); // employeesURI = rootCollection.getLink("employees").getHref(); // } // // void handlePossibleErrors(Collection collection) { // if(collection.hasError()) { // throw new RuntimeException(collection.getError().getMessage()); // } // } // // public void addNewEmployee(Employee employee) { // Collection employees = httpCjClient.readCollection(employeesURI); // // Template template = employees.getTemplate(); // template.fill(new EmployeeTransformer().transform(employee)); // // httpCjClient.addItem(employees.getHref(), template); // } // // public List<Employee> getEmployeesOfDepartment(String departmentName) { // Collection departments = httpCjClient.readCollection(departmentsURI); // // Iterator<Collection> collectionIterator = new CollectionIterator(departments, httpCjClient); // // List<Item> items = new LinkedList<>(); // while(collectionIterator.hasNext()) { // Collection subset = collectionIterator.next(); // items.addAll(subset.getItems()); // } // // // Item foundItem = null; // for(Item item : items) { // if(item.getString("dept_name").equalsIgnoreCase(departmentName)) { // foundItem=item; // } // } // // if(foundItem == null) { // return Collections.emptyList(); // } // // Collection department = httpCjClient.readCollection(foundItem.getHref()); // // Collection employees = httpCjClient.readCollection(department.getLink("employees").getHref()); // // Iterator<Collection> employeeIter = new CollectionIterator(employees, httpCjClient); // List<Item> employeeItems = new LinkedList<>(); // while(employeeIter.hasNext()) { // employeeItems.addAll(employeeIter.next().getItems()); // System.out.println(employeeItems.size()); // } // // Collection finalEmployees = new Collection(employees.getHref(), employeeItems, employees.getQueries(), employees.getLinks(), employees.getTemplate()); // // return finalEmployees.transform(new EmployeeTransformer()); // } // // public List<Department> getAllDepartments() { // Collection departments = httpCjClient.readCollection(departmentsURI); // // Iterator<Collection> iterator = new CollectionIterator(departments, httpCjClient); // List<Item> items = new LinkedList<>(); // while(iterator.hasNext()) { // System.out.println("itearion!"); // items.addAll(iterator.next().getItems()); // } // // handlePossibleErrors(departments); // // Collection finalCollection = new Collection(departments.getHref(), items, departments.getQueries(), departments.getLinks(), departments.getTemplate()); // // return finalCollection.transform(new DepratmentTransformer()); // } // // public List<Employee> getAllEmployees() { // Collection employees = httpCjClient.readCollection(employeesURI); // // handlePossibleErrors(employees); // // return employees.transform(new EmployeeTransformer()); // } // // public List<Employee> findEmployeeByName(String name) { // Collection employees = httpCjClient.readCollection(employeesURI); // Query searchQuery = employees.getQuery("search"); // // Query filledQuery = searchQuery.set("name", name); // // return httpCjClient.follow(filledQuery).transform(new EmployeeTransformer()); // } // // private class CollectionIterator implements Iterator<Collection> { // // private Collection context; // private final CjClient cjClient; // // public CollectionIterator(Collection context, CjClient cjClient) { // this.context = context; // this.cjClient = cjClient; // } // // @Override // public boolean hasNext() { // return context != null && context.getLink("next") != null; // } // // @Override // public Collection next() { // // URI nextUri = context.getLink("next").getHref(); // // Collection next = cjClient.readCollection(nextUri); // context = next; // // return next; // } // // @Override // public void remove() { // } // } // }
import de.fesere.hypermedia.cj.example.employeeDB.Department; import de.fesere.hypermedia.cj.example.employeeDB.EmployeeDB; import org.junit.Ignore; import org.junit.Test; import java.util.List;
package de.fesere.hypermedia.cj.model; public class IntegrationTest { @Ignore("Runs against a real API") @Test public void test() { EmployeeDB employeeDB = new EmployeeDB();
// Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/Department.java // public class Department { // private final String nr; // private final String name; // private final URI link; // // public Department(String nr, String name, URI link) { // this.nr = nr; // this.name = name; // this.link = link; // } // // public URI getLink(){ // return link; // } // // // public String toString() { // return "Department [nr: " + nr + ", name:" + name+"]"; // } // } // // Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/EmployeeDB.java // public class EmployeeDB { // // private final CjClient httpCjClient = new CjClient(new ApacheClient()); // // private URI departmentsURI = null; // private final URI employeesURI; // // // public EmployeeDB() { // URI START = URI.create("http://employee.herokuapp.com"); // Collection rootCollection = httpCjClient.readCollection(START); // // handlePossibleErrors(rootCollection); // // departmentsURI = rootCollection.getLink("departments").getHref(); // employeesURI = rootCollection.getLink("employees").getHref(); // } // // void handlePossibleErrors(Collection collection) { // if(collection.hasError()) { // throw new RuntimeException(collection.getError().getMessage()); // } // } // // public void addNewEmployee(Employee employee) { // Collection employees = httpCjClient.readCollection(employeesURI); // // Template template = employees.getTemplate(); // template.fill(new EmployeeTransformer().transform(employee)); // // httpCjClient.addItem(employees.getHref(), template); // } // // public List<Employee> getEmployeesOfDepartment(String departmentName) { // Collection departments = httpCjClient.readCollection(departmentsURI); // // Iterator<Collection> collectionIterator = new CollectionIterator(departments, httpCjClient); // // List<Item> items = new LinkedList<>(); // while(collectionIterator.hasNext()) { // Collection subset = collectionIterator.next(); // items.addAll(subset.getItems()); // } // // // Item foundItem = null; // for(Item item : items) { // if(item.getString("dept_name").equalsIgnoreCase(departmentName)) { // foundItem=item; // } // } // // if(foundItem == null) { // return Collections.emptyList(); // } // // Collection department = httpCjClient.readCollection(foundItem.getHref()); // // Collection employees = httpCjClient.readCollection(department.getLink("employees").getHref()); // // Iterator<Collection> employeeIter = new CollectionIterator(employees, httpCjClient); // List<Item> employeeItems = new LinkedList<>(); // while(employeeIter.hasNext()) { // employeeItems.addAll(employeeIter.next().getItems()); // System.out.println(employeeItems.size()); // } // // Collection finalEmployees = new Collection(employees.getHref(), employeeItems, employees.getQueries(), employees.getLinks(), employees.getTemplate()); // // return finalEmployees.transform(new EmployeeTransformer()); // } // // public List<Department> getAllDepartments() { // Collection departments = httpCjClient.readCollection(departmentsURI); // // Iterator<Collection> iterator = new CollectionIterator(departments, httpCjClient); // List<Item> items = new LinkedList<>(); // while(iterator.hasNext()) { // System.out.println("itearion!"); // items.addAll(iterator.next().getItems()); // } // // handlePossibleErrors(departments); // // Collection finalCollection = new Collection(departments.getHref(), items, departments.getQueries(), departments.getLinks(), departments.getTemplate()); // // return finalCollection.transform(new DepratmentTransformer()); // } // // public List<Employee> getAllEmployees() { // Collection employees = httpCjClient.readCollection(employeesURI); // // handlePossibleErrors(employees); // // return employees.transform(new EmployeeTransformer()); // } // // public List<Employee> findEmployeeByName(String name) { // Collection employees = httpCjClient.readCollection(employeesURI); // Query searchQuery = employees.getQuery("search"); // // Query filledQuery = searchQuery.set("name", name); // // return httpCjClient.follow(filledQuery).transform(new EmployeeTransformer()); // } // // private class CollectionIterator implements Iterator<Collection> { // // private Collection context; // private final CjClient cjClient; // // public CollectionIterator(Collection context, CjClient cjClient) { // this.context = context; // this.cjClient = cjClient; // } // // @Override // public boolean hasNext() { // return context != null && context.getLink("next") != null; // } // // @Override // public Collection next() { // // URI nextUri = context.getLink("next").getHref(); // // Collection next = cjClient.readCollection(nextUri); // context = next; // // return next; // } // // @Override // public void remove() { // } // } // } // Path: src/test/java/de/fesere/hypermedia/cj/model/IntegrationTest.java import de.fesere.hypermedia.cj.example.employeeDB.Department; import de.fesere.hypermedia.cj.example.employeeDB.EmployeeDB; import org.junit.Ignore; import org.junit.Test; import java.util.List; package de.fesere.hypermedia.cj.model; public class IntegrationTest { @Ignore("Runs against a real API") @Test public void test() { EmployeeDB employeeDB = new EmployeeDB();
List<Department> allDepartments = employeeDB.getAllDepartments();
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/builder/TemplateBuilder.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonPropertyOrder({"href", "data", "links"}) // public class Item { // private final URI href; // private final List<DataEntry> data = new ArrayList<>(); // private List<Link> links = new ArrayList<>(); // // // public Item() { // this(Collections.<DataEntry>emptyList()); // } // // public Item(List<DataEntry> data) { // this((URI) null); // if (data != null) { // this.data.addAll(data); // } // } // // public Item(URI href) { // this(href, Collections.<Link>emptyList()); // } // // @JsonCreator // public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { // this.href = href; // this.links = links; // } // // public Item(URI href, List<DataEntry> entries, List<Link> links) { // this(href, links); // this.data.addAll(entries); // } // // public URI getHref() { // return this.href; // } // // public void addData(DataEntry dataEntry) { // data.add(dataEntry); // } // // public List<DataEntry> getData() { // return new ArrayList<>(data); // } // // public List<Link> getLinks() { // return links; // } // // public String getString(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof StringDataEntry) { // return ((StringDataEntry) found).getValue(); // } // throw new PropertyNotFoundException(name, href, String.class); // } // // public boolean isNullValue(String name) { // DataEntry found = findDataEntry(name); // // return found instanceof NullDataEntry; // } // // public int getInt(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Integer.parseInt(value.toString()); // // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public double getDouble(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Double.parseDouble(value.toString()); // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public boolean getBoolean(String name) { // DataEntry entry = findDataEntry(name); // if (entry instanceof BooleanDataEntry) { // return (boolean) entry.getValue(); // } // // throw new PropertyNotFoundException(name, href, Boolean.class); // } // // private DataEntry findDataEntry(String name) { // DataEntry found = null; // for (DataEntry entry : data) { // if (entry.getName().equals(name)) { // found = entry; // break; // } // } // if (found == null) { // throw new ElementNotFoundException("Did not find property '" + name + "' in '" + href + "'"); // } // return found; // } // // public Map<String, Object> extractDataMap() { // Map<String, Object> result = new HashMap<>(); // for (DataEntry entry : data) { // result.put(entry.getName(), entry.getValue()); // } // // return result; // } // // public Object getObject(String entryName) { // DataEntry entry = findDataEntry(entryName); // // return entry.getValue(); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Template.java // @JsonTypeName("template") // @JsonIgnoreProperties(ignoreUnknown = true) // public class Template implements Wrapped { // // private List<DataEntry> data; // // public Template(@JsonProperty("data") List<DataEntry> data) { // this.data = data; // } // // public List<DataEntry> getData() { // return new LinkedList<>(data); // } // // public void fill(Item item) { // List<DataEntry> filledDataEntries = new LinkedList<>(); // // for(DataEntry entry : data) { // String name = entry.getName(); // String prompt = entry.getPrompt(); // Object value = item.getObject(name); // // DataEntry filled = DataEntryFactory.create(name, value, prompt); // filledDataEntries.add(filled); // } // // this.data = filledDataEntries; // } // // public <T> T convert(ReadTransformation<T> transformation) { // DataEntryTransformer<T> dataEntryTransformer = new DataEntryTransformer<>(transformation); // return dataEntryTransformer.transform(data); // } // // public Map<String, Object> getDataMap() { // Map<String, Object> dataEntries = new HashMap<>(); // for(DataEntry entry : data) { // dataEntries.put(entry.getName(), entry.getValue()); // } // // return dataEntries; // } // }
import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.Item; import de.fesere.hypermedia.cj.model.Template; import java.util.LinkedList; import java.util.List;
package de.fesere.hypermedia.cj.model.builder; public class TemplateBuilder { private List<DataEntry> entries = new LinkedList<>();
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonPropertyOrder({"href", "data", "links"}) // public class Item { // private final URI href; // private final List<DataEntry> data = new ArrayList<>(); // private List<Link> links = new ArrayList<>(); // // // public Item() { // this(Collections.<DataEntry>emptyList()); // } // // public Item(List<DataEntry> data) { // this((URI) null); // if (data != null) { // this.data.addAll(data); // } // } // // public Item(URI href) { // this(href, Collections.<Link>emptyList()); // } // // @JsonCreator // public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { // this.href = href; // this.links = links; // } // // public Item(URI href, List<DataEntry> entries, List<Link> links) { // this(href, links); // this.data.addAll(entries); // } // // public URI getHref() { // return this.href; // } // // public void addData(DataEntry dataEntry) { // data.add(dataEntry); // } // // public List<DataEntry> getData() { // return new ArrayList<>(data); // } // // public List<Link> getLinks() { // return links; // } // // public String getString(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof StringDataEntry) { // return ((StringDataEntry) found).getValue(); // } // throw new PropertyNotFoundException(name, href, String.class); // } // // public boolean isNullValue(String name) { // DataEntry found = findDataEntry(name); // // return found instanceof NullDataEntry; // } // // public int getInt(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Integer.parseInt(value.toString()); // // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public double getDouble(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Double.parseDouble(value.toString()); // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public boolean getBoolean(String name) { // DataEntry entry = findDataEntry(name); // if (entry instanceof BooleanDataEntry) { // return (boolean) entry.getValue(); // } // // throw new PropertyNotFoundException(name, href, Boolean.class); // } // // private DataEntry findDataEntry(String name) { // DataEntry found = null; // for (DataEntry entry : data) { // if (entry.getName().equals(name)) { // found = entry; // break; // } // } // if (found == null) { // throw new ElementNotFoundException("Did not find property '" + name + "' in '" + href + "'"); // } // return found; // } // // public Map<String, Object> extractDataMap() { // Map<String, Object> result = new HashMap<>(); // for (DataEntry entry : data) { // result.put(entry.getName(), entry.getValue()); // } // // return result; // } // // public Object getObject(String entryName) { // DataEntry entry = findDataEntry(entryName); // // return entry.getValue(); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Template.java // @JsonTypeName("template") // @JsonIgnoreProperties(ignoreUnknown = true) // public class Template implements Wrapped { // // private List<DataEntry> data; // // public Template(@JsonProperty("data") List<DataEntry> data) { // this.data = data; // } // // public List<DataEntry> getData() { // return new LinkedList<>(data); // } // // public void fill(Item item) { // List<DataEntry> filledDataEntries = new LinkedList<>(); // // for(DataEntry entry : data) { // String name = entry.getName(); // String prompt = entry.getPrompt(); // Object value = item.getObject(name); // // DataEntry filled = DataEntryFactory.create(name, value, prompt); // filledDataEntries.add(filled); // } // // this.data = filledDataEntries; // } // // public <T> T convert(ReadTransformation<T> transformation) { // DataEntryTransformer<T> dataEntryTransformer = new DataEntryTransformer<>(transformation); // return dataEntryTransformer.transform(data); // } // // public Map<String, Object> getDataMap() { // Map<String, Object> dataEntries = new HashMap<>(); // for(DataEntry entry : data) { // dataEntries.put(entry.getName(), entry.getValue()); // } // // return dataEntries; // } // } // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/TemplateBuilder.java import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.Item; import de.fesere.hypermedia.cj.model.Template; import java.util.LinkedList; import java.util.List; package de.fesere.hypermedia.cj.model.builder; public class TemplateBuilder { private List<DataEntry> entries = new LinkedList<>();
public TemplateBuilder filledFromItem(Item item) {
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/serialization/ObjectMapperConfig.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // }
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.module.SimpleModule; import de.fesere.hypermedia.cj.model.DataEntry;
package de.fesere.hypermedia.cj.serialization; public class ObjectMapperConfig { public ObjectMapper getConfiguredObjectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new WrapperModule()); mapper.enable(SerializationFeature.INDENT_OUTPUT); return mapper; } public static class WrapperModule extends SimpleModule { public WrapperModule() { addSerializer(Wrapper.class, new WrapperSerializer()); addDeserializer(Wrapper.class, new WrapperDeserializer());
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // Path: src/main/java/de/fesere/hypermedia/cj/serialization/ObjectMapperConfig.java import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.module.SimpleModule; import de.fesere.hypermedia.cj.model.DataEntry; package de.fesere.hypermedia.cj.serialization; public class ObjectMapperConfig { public ObjectMapper getConfiguredObjectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new WrapperModule()); mapper.enable(SerializationFeature.INDENT_OUTPUT); return mapper; } public static class WrapperModule extends SimpleModule { public WrapperModule() { addSerializer(Wrapper.class, new WrapperSerializer()); addDeserializer(Wrapper.class, new WrapperDeserializer());
addSerializer(DataEntry.class, new DataEntrySerializer());
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/transformer/TwoWayTransformer.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonPropertyOrder({"href", "data", "links"}) // public class Item { // private final URI href; // private final List<DataEntry> data = new ArrayList<>(); // private List<Link> links = new ArrayList<>(); // // // public Item() { // this(Collections.<DataEntry>emptyList()); // } // // public Item(List<DataEntry> data) { // this((URI) null); // if (data != null) { // this.data.addAll(data); // } // } // // public Item(URI href) { // this(href, Collections.<Link>emptyList()); // } // // @JsonCreator // public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { // this.href = href; // this.links = links; // } // // public Item(URI href, List<DataEntry> entries, List<Link> links) { // this(href, links); // this.data.addAll(entries); // } // // public URI getHref() { // return this.href; // } // // public void addData(DataEntry dataEntry) { // data.add(dataEntry); // } // // public List<DataEntry> getData() { // return new ArrayList<>(data); // } // // public List<Link> getLinks() { // return links; // } // // public String getString(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof StringDataEntry) { // return ((StringDataEntry) found).getValue(); // } // throw new PropertyNotFoundException(name, href, String.class); // } // // public boolean isNullValue(String name) { // DataEntry found = findDataEntry(name); // // return found instanceof NullDataEntry; // } // // public int getInt(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Integer.parseInt(value.toString()); // // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public double getDouble(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Double.parseDouble(value.toString()); // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public boolean getBoolean(String name) { // DataEntry entry = findDataEntry(name); // if (entry instanceof BooleanDataEntry) { // return (boolean) entry.getValue(); // } // // throw new PropertyNotFoundException(name, href, Boolean.class); // } // // private DataEntry findDataEntry(String name) { // DataEntry found = null; // for (DataEntry entry : data) { // if (entry.getName().equals(name)) { // found = entry; // break; // } // } // if (found == null) { // throw new ElementNotFoundException("Did not find property '" + name + "' in '" + href + "'"); // } // return found; // } // // public Map<String, Object> extractDataMap() { // Map<String, Object> result = new HashMap<>(); // for (DataEntry entry : data) { // result.put(entry.getName(), entry.getValue()); // } // // return result; // } // // public Object getObject(String entryName) { // DataEntry entry = findDataEntry(entryName); // // return entry.getValue(); // } // }
import de.fesere.hypermedia.cj.model.Item;
package de.fesere.hypermedia.cj.transformer; public abstract class TwoWayTransformer<T> implements ReadTransformation<T>, WriteTransformer<T> { @Override
// Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonPropertyOrder({"href", "data", "links"}) // public class Item { // private final URI href; // private final List<DataEntry> data = new ArrayList<>(); // private List<Link> links = new ArrayList<>(); // // // public Item() { // this(Collections.<DataEntry>emptyList()); // } // // public Item(List<DataEntry> data) { // this((URI) null); // if (data != null) { // this.data.addAll(data); // } // } // // public Item(URI href) { // this(href, Collections.<Link>emptyList()); // } // // @JsonCreator // public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { // this.href = href; // this.links = links; // } // // public Item(URI href, List<DataEntry> entries, List<Link> links) { // this(href, links); // this.data.addAll(entries); // } // // public URI getHref() { // return this.href; // } // // public void addData(DataEntry dataEntry) { // data.add(dataEntry); // } // // public List<DataEntry> getData() { // return new ArrayList<>(data); // } // // public List<Link> getLinks() { // return links; // } // // public String getString(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof StringDataEntry) { // return ((StringDataEntry) found).getValue(); // } // throw new PropertyNotFoundException(name, href, String.class); // } // // public boolean isNullValue(String name) { // DataEntry found = findDataEntry(name); // // return found instanceof NullDataEntry; // } // // public int getInt(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Integer.parseInt(value.toString()); // // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public double getDouble(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Double.parseDouble(value.toString()); // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public boolean getBoolean(String name) { // DataEntry entry = findDataEntry(name); // if (entry instanceof BooleanDataEntry) { // return (boolean) entry.getValue(); // } // // throw new PropertyNotFoundException(name, href, Boolean.class); // } // // private DataEntry findDataEntry(String name) { // DataEntry found = null; // for (DataEntry entry : data) { // if (entry.getName().equals(name)) { // found = entry; // break; // } // } // if (found == null) { // throw new ElementNotFoundException("Did not find property '" + name + "' in '" + href + "'"); // } // return found; // } // // public Map<String, Object> extractDataMap() { // Map<String, Object> result = new HashMap<>(); // for (DataEntry entry : data) { // result.put(entry.getName(), entry.getValue()); // } // // return result; // } // // public Object getObject(String entryName) { // DataEntry entry = findDataEntry(entryName); // // return entry.getValue(); // } // } // Path: src/main/java/de/fesere/hypermedia/cj/transformer/TwoWayTransformer.java import de.fesere.hypermedia.cj.model.Item; package de.fesere.hypermedia.cj.transformer; public abstract class TwoWayTransformer<T> implements ReadTransformation<T>, WriteTransformer<T> { @Override
public T transform(Item item) {
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/example/employeeDB/EmployeeDB.java
// Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/transformations/DepratmentTransformer.java // public class DepratmentTransformer implements ReadTransformation<Department> { // @Override // public Department transform(Item item) { // return new Department(item.getString("dept_no"), item.getString("dept_name"), item.getHref()); // } // } // // Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/transformations/EmployeeTransformer.java // public class EmployeeTransformer extends TwoWayTransformer<Employee> { // // @Override // public Employee transform(Item item) { // // return new Employee(item.getInt("emp_no"), // item.getString("birth_date"), // item.getString("first_name"), // item.getString("last_name"), // item.getString("gender")); // } // // @Override // public Item transform(Employee input) { // Item item = new Item(); // item.addData(create("birth_date", input.getBirthday())); // item.addData(create("first_name", input.getFirstName())); // item.addData(create("last_name", input.getLastName())); // item.addData(create("gender", input.getGender())); // // return item; // } // }
import de.fesere.hypermedia.cj.example.employeeDB.transformations.DepratmentTransformer; import de.fesere.hypermedia.cj.example.employeeDB.transformations.EmployeeTransformer; import de.fesere.hypermedia.cj.model.*; import java.net.URI; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List;
package de.fesere.hypermedia.cj.example.employeeDB; public class EmployeeDB { private final CjClient httpCjClient = new CjClient(new ApacheClient()); private URI departmentsURI = null; private final URI employeesURI; public EmployeeDB() { URI START = URI.create("http://employee.herokuapp.com"); Collection rootCollection = httpCjClient.readCollection(START); handlePossibleErrors(rootCollection); departmentsURI = rootCollection.getLink("departments").getHref(); employeesURI = rootCollection.getLink("employees").getHref(); } void handlePossibleErrors(Collection collection) { if(collection.hasError()) { throw new RuntimeException(collection.getError().getMessage()); } } public void addNewEmployee(Employee employee) { Collection employees = httpCjClient.readCollection(employeesURI); Template template = employees.getTemplate();
// Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/transformations/DepratmentTransformer.java // public class DepratmentTransformer implements ReadTransformation<Department> { // @Override // public Department transform(Item item) { // return new Department(item.getString("dept_no"), item.getString("dept_name"), item.getHref()); // } // } // // Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/transformations/EmployeeTransformer.java // public class EmployeeTransformer extends TwoWayTransformer<Employee> { // // @Override // public Employee transform(Item item) { // // return new Employee(item.getInt("emp_no"), // item.getString("birth_date"), // item.getString("first_name"), // item.getString("last_name"), // item.getString("gender")); // } // // @Override // public Item transform(Employee input) { // Item item = new Item(); // item.addData(create("birth_date", input.getBirthday())); // item.addData(create("first_name", input.getFirstName())); // item.addData(create("last_name", input.getLastName())); // item.addData(create("gender", input.getGender())); // // return item; // } // } // Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/EmployeeDB.java import de.fesere.hypermedia.cj.example.employeeDB.transformations.DepratmentTransformer; import de.fesere.hypermedia.cj.example.employeeDB.transformations.EmployeeTransformer; import de.fesere.hypermedia.cj.model.*; import java.net.URI; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; package de.fesere.hypermedia.cj.example.employeeDB; public class EmployeeDB { private final CjClient httpCjClient = new CjClient(new ApacheClient()); private URI departmentsURI = null; private final URI employeesURI; public EmployeeDB() { URI START = URI.create("http://employee.herokuapp.com"); Collection rootCollection = httpCjClient.readCollection(START); handlePossibleErrors(rootCollection); departmentsURI = rootCollection.getLink("departments").getHref(); employeesURI = rootCollection.getLink("employees").getHref(); } void handlePossibleErrors(Collection collection) { if(collection.hasError()) { throw new RuntimeException(collection.getError().getMessage()); } } public void addNewEmployee(Employee employee) { Collection employees = httpCjClient.readCollection(employeesURI); Template template = employees.getTemplate();
template.fill(new EmployeeTransformer().transform(employee));
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/example/employeeDB/EmployeeDB.java
// Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/transformations/DepratmentTransformer.java // public class DepratmentTransformer implements ReadTransformation<Department> { // @Override // public Department transform(Item item) { // return new Department(item.getString("dept_no"), item.getString("dept_name"), item.getHref()); // } // } // // Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/transformations/EmployeeTransformer.java // public class EmployeeTransformer extends TwoWayTransformer<Employee> { // // @Override // public Employee transform(Item item) { // // return new Employee(item.getInt("emp_no"), // item.getString("birth_date"), // item.getString("first_name"), // item.getString("last_name"), // item.getString("gender")); // } // // @Override // public Item transform(Employee input) { // Item item = new Item(); // item.addData(create("birth_date", input.getBirthday())); // item.addData(create("first_name", input.getFirstName())); // item.addData(create("last_name", input.getLastName())); // item.addData(create("gender", input.getGender())); // // return item; // } // }
import de.fesere.hypermedia.cj.example.employeeDB.transformations.DepratmentTransformer; import de.fesere.hypermedia.cj.example.employeeDB.transformations.EmployeeTransformer; import de.fesere.hypermedia.cj.model.*; import java.net.URI; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List;
Collection department = httpCjClient.readCollection(foundItem.getHref()); Collection employees = httpCjClient.readCollection(department.getLink("employees").getHref()); Iterator<Collection> employeeIter = new CollectionIterator(employees, httpCjClient); List<Item> employeeItems = new LinkedList<>(); while(employeeIter.hasNext()) { employeeItems.addAll(employeeIter.next().getItems()); System.out.println(employeeItems.size()); } Collection finalEmployees = new Collection(employees.getHref(), employeeItems, employees.getQueries(), employees.getLinks(), employees.getTemplate()); return finalEmployees.transform(new EmployeeTransformer()); } public List<Department> getAllDepartments() { Collection departments = httpCjClient.readCollection(departmentsURI); Iterator<Collection> iterator = new CollectionIterator(departments, httpCjClient); List<Item> items = new LinkedList<>(); while(iterator.hasNext()) { System.out.println("itearion!"); items.addAll(iterator.next().getItems()); } handlePossibleErrors(departments); Collection finalCollection = new Collection(departments.getHref(), items, departments.getQueries(), departments.getLinks(), departments.getTemplate());
// Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/transformations/DepratmentTransformer.java // public class DepratmentTransformer implements ReadTransformation<Department> { // @Override // public Department transform(Item item) { // return new Department(item.getString("dept_no"), item.getString("dept_name"), item.getHref()); // } // } // // Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/transformations/EmployeeTransformer.java // public class EmployeeTransformer extends TwoWayTransformer<Employee> { // // @Override // public Employee transform(Item item) { // // return new Employee(item.getInt("emp_no"), // item.getString("birth_date"), // item.getString("first_name"), // item.getString("last_name"), // item.getString("gender")); // } // // @Override // public Item transform(Employee input) { // Item item = new Item(); // item.addData(create("birth_date", input.getBirthday())); // item.addData(create("first_name", input.getFirstName())); // item.addData(create("last_name", input.getLastName())); // item.addData(create("gender", input.getGender())); // // return item; // } // } // Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/EmployeeDB.java import de.fesere.hypermedia.cj.example.employeeDB.transformations.DepratmentTransformer; import de.fesere.hypermedia.cj.example.employeeDB.transformations.EmployeeTransformer; import de.fesere.hypermedia.cj.model.*; import java.net.URI; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; Collection department = httpCjClient.readCollection(foundItem.getHref()); Collection employees = httpCjClient.readCollection(department.getLink("employees").getHref()); Iterator<Collection> employeeIter = new CollectionIterator(employees, httpCjClient); List<Item> employeeItems = new LinkedList<>(); while(employeeIter.hasNext()) { employeeItems.addAll(employeeIter.next().getItems()); System.out.println(employeeItems.size()); } Collection finalEmployees = new Collection(employees.getHref(), employeeItems, employees.getQueries(), employees.getLinks(), employees.getTemplate()); return finalEmployees.transform(new EmployeeTransformer()); } public List<Department> getAllDepartments() { Collection departments = httpCjClient.readCollection(departmentsURI); Iterator<Collection> iterator = new CollectionIterator(departments, httpCjClient); List<Item> items = new LinkedList<>(); while(iterator.hasNext()) { System.out.println("itearion!"); items.addAll(iterator.next().getItems()); } handlePossibleErrors(departments); Collection finalCollection = new Collection(departments.getHref(), items, departments.getQueries(), departments.getLinks(), departments.getTemplate());
return finalCollection.transform(new DepratmentTransformer());
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/CollectionWithTypedItemsTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/CollectionBuilder.java // public class CollectionBuilder<T> { // // private final WriteTransformer<T> transformer; // private UriConstructor uriConstructor; // private LinkBuilder linkBuilder; // private Template temaplate; // private List<Query> queries = new LinkedList<>(); // private List<Item> items = new LinkedList<>(); // // public CollectionBuilder(URI href, WriteTransformer<T> transformer) { // this.transformer = transformer; // if (href == null) { // throw new IllegalArgumentException("URI must not be null!"); // } // uriConstructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public CollectionBuilder(URI href) { // this(href, null); // } // // public CollectionBuilder addTemplate(Template temaplte) { // this.temaplate = temaplte; // return this; // } // // public CollectionBuilder addQuery(Query query) { // queries.add(query); // return this; // } // // public CollectionBuilder addQuery(Query query, String relativURL) { // URI absoluteURL = uriConstructor.buildAbsoluteHrefFromRelative(relativURL); // // Query temp = new Query(absoluteURL, query.getRel(), query.getPrompt(), query.getData()); // // return addQuery(temp); // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public CollectionBuilder addObject(T object) { // Item item = transformer.transform(object); // if (item != null) { // addItem(item); // } // // return this; // } // // public CollectionBuilder addItem(Item item) { // items.add(item); // return this; // } // // public Collection build() { // return new Collection(uriConstructor.getBase(), items, queries, linkBuilder.build(), temaplate); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java // public class ItemBuilder { // // private List<DataEntry> dataEntries = new LinkedList<>(); // private UriConstructor constructor; // private LinkBuilder linkBuilder; // // public ItemBuilder(URI href) { // constructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public ItemBuilder addData(DataEntry entry) { // dataEntries.add(entry); // return this; // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public Item build() { // return new Item(constructor.getBase(), dataEntries, linkBuilder.build()); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // }
import de.fesere.hypermedia.cj.model.builder.CollectionBuilder; import de.fesere.hypermedia.cj.model.builder.ItemBuilder; import org.junit.Test; import java.net.URI; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.closeTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.Is.is;
package de.fesere.hypermedia.cj.model; public class CollectionWithTypedItemsTest extends SerializationTestBase { @Test public void testWriteJsonWithMultipleTypes() { String json = readFile("/examples/read-collection-with-typed-data.json");
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/CollectionBuilder.java // public class CollectionBuilder<T> { // // private final WriteTransformer<T> transformer; // private UriConstructor uriConstructor; // private LinkBuilder linkBuilder; // private Template temaplate; // private List<Query> queries = new LinkedList<>(); // private List<Item> items = new LinkedList<>(); // // public CollectionBuilder(URI href, WriteTransformer<T> transformer) { // this.transformer = transformer; // if (href == null) { // throw new IllegalArgumentException("URI must not be null!"); // } // uriConstructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public CollectionBuilder(URI href) { // this(href, null); // } // // public CollectionBuilder addTemplate(Template temaplte) { // this.temaplate = temaplte; // return this; // } // // public CollectionBuilder addQuery(Query query) { // queries.add(query); // return this; // } // // public CollectionBuilder addQuery(Query query, String relativURL) { // URI absoluteURL = uriConstructor.buildAbsoluteHrefFromRelative(relativURL); // // Query temp = new Query(absoluteURL, query.getRel(), query.getPrompt(), query.getData()); // // return addQuery(temp); // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public CollectionBuilder addObject(T object) { // Item item = transformer.transform(object); // if (item != null) { // addItem(item); // } // // return this; // } // // public CollectionBuilder addItem(Item item) { // items.add(item); // return this; // } // // public Collection build() { // return new Collection(uriConstructor.getBase(), items, queries, linkBuilder.build(), temaplate); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java // public class ItemBuilder { // // private List<DataEntry> dataEntries = new LinkedList<>(); // private UriConstructor constructor; // private LinkBuilder linkBuilder; // // public ItemBuilder(URI href) { // constructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public ItemBuilder addData(DataEntry entry) { // dataEntries.add(entry); // return this; // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public Item build() { // return new Item(constructor.getBase(), dataEntries, linkBuilder.build()); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // Path: src/test/java/de/fesere/hypermedia/cj/model/CollectionWithTypedItemsTest.java import de.fesere.hypermedia.cj.model.builder.CollectionBuilder; import de.fesere.hypermedia.cj.model.builder.ItemBuilder; import org.junit.Test; import java.net.URI; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.closeTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.Is.is; package de.fesere.hypermedia.cj.model; public class CollectionWithTypedItemsTest extends SerializationTestBase { @Test public void testWriteJsonWithMultipleTypes() { String json = readFile("/examples/read-collection-with-typed-data.json");
CollectionBuilder builder = new CollectionBuilder(URI.create("http://example.org/friends/"));
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/CollectionWithTypedItemsTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/CollectionBuilder.java // public class CollectionBuilder<T> { // // private final WriteTransformer<T> transformer; // private UriConstructor uriConstructor; // private LinkBuilder linkBuilder; // private Template temaplate; // private List<Query> queries = new LinkedList<>(); // private List<Item> items = new LinkedList<>(); // // public CollectionBuilder(URI href, WriteTransformer<T> transformer) { // this.transformer = transformer; // if (href == null) { // throw new IllegalArgumentException("URI must not be null!"); // } // uriConstructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public CollectionBuilder(URI href) { // this(href, null); // } // // public CollectionBuilder addTemplate(Template temaplte) { // this.temaplate = temaplte; // return this; // } // // public CollectionBuilder addQuery(Query query) { // queries.add(query); // return this; // } // // public CollectionBuilder addQuery(Query query, String relativURL) { // URI absoluteURL = uriConstructor.buildAbsoluteHrefFromRelative(relativURL); // // Query temp = new Query(absoluteURL, query.getRel(), query.getPrompt(), query.getData()); // // return addQuery(temp); // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public CollectionBuilder addObject(T object) { // Item item = transformer.transform(object); // if (item != null) { // addItem(item); // } // // return this; // } // // public CollectionBuilder addItem(Item item) { // items.add(item); // return this; // } // // public Collection build() { // return new Collection(uriConstructor.getBase(), items, queries, linkBuilder.build(), temaplate); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java // public class ItemBuilder { // // private List<DataEntry> dataEntries = new LinkedList<>(); // private UriConstructor constructor; // private LinkBuilder linkBuilder; // // public ItemBuilder(URI href) { // constructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public ItemBuilder addData(DataEntry entry) { // dataEntries.add(entry); // return this; // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public Item build() { // return new Item(constructor.getBase(), dataEntries, linkBuilder.build()); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // }
import de.fesere.hypermedia.cj.model.builder.CollectionBuilder; import de.fesere.hypermedia.cj.model.builder.ItemBuilder; import org.junit.Test; import java.net.URI; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.closeTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.Is.is;
package de.fesere.hypermedia.cj.model; public class CollectionWithTypedItemsTest extends SerializationTestBase { @Test public void testWriteJsonWithMultipleTypes() { String json = readFile("/examples/read-collection-with-typed-data.json"); CollectionBuilder builder = new CollectionBuilder(URI.create("http://example.org/friends/"));
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/CollectionBuilder.java // public class CollectionBuilder<T> { // // private final WriteTransformer<T> transformer; // private UriConstructor uriConstructor; // private LinkBuilder linkBuilder; // private Template temaplate; // private List<Query> queries = new LinkedList<>(); // private List<Item> items = new LinkedList<>(); // // public CollectionBuilder(URI href, WriteTransformer<T> transformer) { // this.transformer = transformer; // if (href == null) { // throw new IllegalArgumentException("URI must not be null!"); // } // uriConstructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public CollectionBuilder(URI href) { // this(href, null); // } // // public CollectionBuilder addTemplate(Template temaplte) { // this.temaplate = temaplte; // return this; // } // // public CollectionBuilder addQuery(Query query) { // queries.add(query); // return this; // } // // public CollectionBuilder addQuery(Query query, String relativURL) { // URI absoluteURL = uriConstructor.buildAbsoluteHrefFromRelative(relativURL); // // Query temp = new Query(absoluteURL, query.getRel(), query.getPrompt(), query.getData()); // // return addQuery(temp); // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public CollectionBuilder addObject(T object) { // Item item = transformer.transform(object); // if (item != null) { // addItem(item); // } // // return this; // } // // public CollectionBuilder addItem(Item item) { // items.add(item); // return this; // } // // public Collection build() { // return new Collection(uriConstructor.getBase(), items, queries, linkBuilder.build(), temaplate); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java // public class ItemBuilder { // // private List<DataEntry> dataEntries = new LinkedList<>(); // private UriConstructor constructor; // private LinkBuilder linkBuilder; // // public ItemBuilder(URI href) { // constructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public ItemBuilder addData(DataEntry entry) { // dataEntries.add(entry); // return this; // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public Item build() { // return new Item(constructor.getBase(), dataEntries, linkBuilder.build()); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // Path: src/test/java/de/fesere/hypermedia/cj/model/CollectionWithTypedItemsTest.java import de.fesere.hypermedia.cj.model.builder.CollectionBuilder; import de.fesere.hypermedia.cj.model.builder.ItemBuilder; import org.junit.Test; import java.net.URI; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.closeTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.Is.is; package de.fesere.hypermedia.cj.model; public class CollectionWithTypedItemsTest extends SerializationTestBase { @Test public void testWriteJsonWithMultipleTypes() { String json = readFile("/examples/read-collection-with-typed-data.json"); CollectionBuilder builder = new CollectionBuilder(URI.create("http://example.org/friends/"));
ItemBuilder itemBuilder = new ItemBuilder(URI.create("http://example.org/friends/jdoe"));
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/serialization/SerializerTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/Collection.java // @JsonTypeName("collection") // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE) // @JsonPropertyOrder({"version", "href", "links", "error", "items", "queries", "template"}) // public class Collection implements Wrapped{ // // private static final String VERSION = "1.0"; // // @JsonProperty("href") // private final URI href; // // @JsonProperty("items") // private final List<Item> items = new ArrayList<>(); // // @JsonProperty("links") // private final List<Link> links = new ArrayList<>(); // // @JsonProperty("queries") // private final List<Query> queries = new ArrayList<>(); // // @JsonProperty("template") // private Template template; // // @JsonProperty("error") // private Error error; // // // // @JsonCreator() // public Collection(@JsonProperty("href") URI href) { // this.href = href; // } // // public Collection(URI uri, Error error) { // this(uri); // this.error = error; // } // // public Collection(URI href, List<Item> items, List<Query> queries, List<Link>links, Template template) { // this(href); // if(items != null) { // this.items.addAll(items); // } // if(queries != null) { // this.queries.addAll(queries); // } // if(links != null) { // this.links.addAll(links); // } // this.template = template; // } // // public URI getHref() { // return this.href; // } // // public List<Item> getItems() { // throwExceptionOnError(); // // return new ArrayList<>(items); // } // // public List<Link> getLinks() { // throwExceptionOnError(); // // return new ArrayList<>(links); // } // // private void throwExceptionOnError() { // if(hasError()) { // throw new CollectionHasErrorsException(getError()); // } // } // // public List<Query> getQueries() { // throwExceptionOnError(); // // return new ArrayList<>(queries); // } // // // public <T> List<T> transform(ReadTransformation<T> transformer) { // throwExceptionOnError(); // // List<T> result = new ArrayList<>(items.size()); // // for(Item item : items) { // T convertedItem = transformer.transform(item); // if(convertedItem != null) { // result.add(convertedItem); // } // } // // return result; // } // // public boolean hasError() { // return error != null; // } // // public Error getError() { // return error; // } // // public Link getLink(String rel) { // throwExceptionOnError(); // // return findByRel(links,rel); // // // } // // private <T extends Link> T findByRel(List<T> elements, String rel) { // for(T linkable : elements ) { // if(linkable.getRel().equalsIgnoreCase(rel)) { // return linkable; // } // } // // throw new ElementNotFoundException("Did not find element '"+rel+"' in collection " + href ); // } // // public Query getQuery(String rel) { // throwExceptionOnError(); // // return findByRel(queries, rel); // } // // public Template getTemplate() { // throwExceptionOnError(); // return template; // } // // @JsonProperty("version") // public String getVersion() { // return VERSION; // } // }
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import de.fesere.hypermedia.cj.model.Collection; import org.junit.Test; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when;
package de.fesere.hypermedia.cj.serialization; public class SerializerTest { Serializer serializer = new Serializer(); @Test(expected = RuntimeException.class) public void testDeserialize_failsOnException() throws Exception {
// Path: src/main/java/de/fesere/hypermedia/cj/model/Collection.java // @JsonTypeName("collection") // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE) // @JsonPropertyOrder({"version", "href", "links", "error", "items", "queries", "template"}) // public class Collection implements Wrapped{ // // private static final String VERSION = "1.0"; // // @JsonProperty("href") // private final URI href; // // @JsonProperty("items") // private final List<Item> items = new ArrayList<>(); // // @JsonProperty("links") // private final List<Link> links = new ArrayList<>(); // // @JsonProperty("queries") // private final List<Query> queries = new ArrayList<>(); // // @JsonProperty("template") // private Template template; // // @JsonProperty("error") // private Error error; // // // // @JsonCreator() // public Collection(@JsonProperty("href") URI href) { // this.href = href; // } // // public Collection(URI uri, Error error) { // this(uri); // this.error = error; // } // // public Collection(URI href, List<Item> items, List<Query> queries, List<Link>links, Template template) { // this(href); // if(items != null) { // this.items.addAll(items); // } // if(queries != null) { // this.queries.addAll(queries); // } // if(links != null) { // this.links.addAll(links); // } // this.template = template; // } // // public URI getHref() { // return this.href; // } // // public List<Item> getItems() { // throwExceptionOnError(); // // return new ArrayList<>(items); // } // // public List<Link> getLinks() { // throwExceptionOnError(); // // return new ArrayList<>(links); // } // // private void throwExceptionOnError() { // if(hasError()) { // throw new CollectionHasErrorsException(getError()); // } // } // // public List<Query> getQueries() { // throwExceptionOnError(); // // return new ArrayList<>(queries); // } // // // public <T> List<T> transform(ReadTransformation<T> transformer) { // throwExceptionOnError(); // // List<T> result = new ArrayList<>(items.size()); // // for(Item item : items) { // T convertedItem = transformer.transform(item); // if(convertedItem != null) { // result.add(convertedItem); // } // } // // return result; // } // // public boolean hasError() { // return error != null; // } // // public Error getError() { // return error; // } // // public Link getLink(String rel) { // throwExceptionOnError(); // // return findByRel(links,rel); // // // } // // private <T extends Link> T findByRel(List<T> elements, String rel) { // for(T linkable : elements ) { // if(linkable.getRel().equalsIgnoreCase(rel)) { // return linkable; // } // } // // throw new ElementNotFoundException("Did not find element '"+rel+"' in collection " + href ); // } // // public Query getQuery(String rel) { // throwExceptionOnError(); // // return findByRel(queries, rel); // } // // public Template getTemplate() { // throwExceptionOnError(); // return template; // } // // @JsonProperty("version") // public String getVersion() { // return VERSION; // } // } // Path: src/test/java/de/fesere/hypermedia/cj/serialization/SerializerTest.java import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import de.fesere.hypermedia.cj.model.Collection; import org.junit.Test; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; package de.fesere.hypermedia.cj.serialization; public class SerializerTest { Serializer serializer = new Serializer(); @Test(expected = RuntimeException.class) public void testDeserialize_failsOnException() throws Exception {
serializer.deserialize("{----broken----}", Collection.class);
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/serialization/DataEntrySerializer.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NoneDataEntry.java // public class NoneDataEntry extends BaseDataEntry { // // public NoneDataEntry(String name) { // super(name); // } // }
import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.data.NoneDataEntry; import org.apache.commons.lang3.StringUtils; import java.io.IOException;
package de.fesere.hypermedia.cj.serialization; public class DataEntrySerializer extends StdSerializer<DataEntry> { private JsonGenerator jgen; protected DataEntrySerializer() { super(DataEntry.class); } @Override public void serialize(DataEntry entry, JsonGenerator jgen, SerializerProvider provider) throws IOException {
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NoneDataEntry.java // public class NoneDataEntry extends BaseDataEntry { // // public NoneDataEntry(String name) { // super(name); // } // } // Path: src/main/java/de/fesere/hypermedia/cj/serialization/DataEntrySerializer.java import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.data.NoneDataEntry; import org.apache.commons.lang3.StringUtils; import java.io.IOException; package de.fesere.hypermedia.cj.serialization; public class DataEntrySerializer extends StdSerializer<DataEntry> { private JsonGenerator jgen; protected DataEntrySerializer() { super(DataEntry.class); } @Override public void serialize(DataEntry entry, JsonGenerator jgen, SerializerProvider provider) throws IOException {
if (entry instanceof NoneDataEntry) {
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/serialization/Serializer.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/SerializationException.java // public class SerializationException extends RuntimeException { // // public SerializationException(String message) { // super(message); // } // // public SerializationException(String message, Throwable cause) { // super(message, cause); // } // }
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import de.fesere.hypermedia.cj.exceptions.SerializationException; import java.io.IOException;
package de.fesere.hypermedia.cj.serialization; public class Serializer { private final ObjectMapper mapper; public Serializer() { this(new ObjectMapperConfig().getConfiguredObjectMapper()); } protected Serializer(ObjectMapper mapper) { this.mapper = mapper; } public <T> T deserialize(String input, Class<T> responseClass) { if(Wrapped.class.isAssignableFrom(responseClass)) { Object deserializedObject = deserializeWrapped(input); if(deserializedObject.getClass().isAssignableFrom(responseClass)) { return responseClass.cast(deserializedObject); } else {
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/SerializationException.java // public class SerializationException extends RuntimeException { // // public SerializationException(String message) { // super(message); // } // // public SerializationException(String message, Throwable cause) { // super(message, cause); // } // } // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Serializer.java import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import de.fesere.hypermedia.cj.exceptions.SerializationException; import java.io.IOException; package de.fesere.hypermedia.cj.serialization; public class Serializer { private final ObjectMapper mapper; public Serializer() { this(new ObjectMapperConfig().getConfiguredObjectMapper()); } protected Serializer(ObjectMapper mapper) { this.mapper = mapper; } public <T> T deserialize(String input, Class<T> responseClass) { if(Wrapped.class.isAssignableFrom(responseClass)) { Object deserializedObject = deserializeWrapped(input); if(deserializedObject.getClass().isAssignableFrom(responseClass)) { return responseClass.cast(deserializedObject); } else {
throw new SerializationException("input could not be serialized to " + responseClass.getCanonicalName());
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Query.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // }
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import org.apache.commons.lang3.StringUtils; import java.net.URI; import java.util.LinkedList; import java.util.List;
package de.fesere.hypermedia.cj.model; @JsonSerialize @JsonIgnoreProperties(ignoreUnknown = true) public class Query extends Link { private final List<DataEntry> data; @JsonCreator public Query(@JsonProperty("href") URI href, @JsonProperty("rel") String rel, @JsonProperty("prompt") String prompt, @JsonProperty("data") List<DataEntry> data) { super(rel, href, prompt); this.data = new LinkedList<>(data); } public Query(String rel, String prompt, List<DataEntry> data) { this(null, rel, prompt, data); } public List<DataEntry> getData() { return data; } public Query set(String name, Object o) { DataEntry found = findDataEntry(name);
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Query.java import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import org.apache.commons.lang3.StringUtils; import java.net.URI; import java.util.LinkedList; import java.util.List; package de.fesere.hypermedia.cj.model; @JsonSerialize @JsonIgnoreProperties(ignoreUnknown = true) public class Query extends Link { private final List<DataEntry> data; @JsonCreator public Query(@JsonProperty("href") URI href, @JsonProperty("rel") String rel, @JsonProperty("prompt") String prompt, @JsonProperty("data") List<DataEntry> data) { super(rel, href, prompt); this.data = new LinkedList<>(data); } public Query(String rel, String prompt, List<DataEntry> data) { this(null, rel, prompt, data); } public List<DataEntry> getData() { return data; } public Query set(String name, Object o) { DataEntry found = findDataEntry(name);
DataEntry replacement = DataEntryFactory.create(name, o, found.getPrompt());
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Query.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // }
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import org.apache.commons.lang3.StringUtils; import java.net.URI; import java.util.LinkedList; import java.util.List;
super(rel, href, prompt); this.data = new LinkedList<>(data); } public Query(String rel, String prompt, List<DataEntry> data) { this(null, rel, prompt, data); } public List<DataEntry> getData() { return data; } public Query set(String name, Object o) { DataEntry found = findDataEntry(name); DataEntry replacement = DataEntryFactory.create(name, o, found.getPrompt()); data.remove(found); data.add(replacement); return this; } private DataEntry findDataEntry(String name) { for (DataEntry dataEntry : data) { if (dataEntry.getName().equals(name)) { return dataEntry; } }
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Query.java import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import org.apache.commons.lang3.StringUtils; import java.net.URI; import java.util.LinkedList; import java.util.List; super(rel, href, prompt); this.data = new LinkedList<>(data); } public Query(String rel, String prompt, List<DataEntry> data) { this(null, rel, prompt, data); } public List<DataEntry> getData() { return data; } public Query set(String name, Object o) { DataEntry found = findDataEntry(name); DataEntry replacement = DataEntryFactory.create(name, o, found.getPrompt()); data.remove(found); data.add(replacement); return this; } private DataEntry findDataEntry(String name) { for (DataEntry dataEntry : data) { if (dataEntry.getName().equals(name)) { return dataEntry; } }
throw new ElementNotFoundException("Did not find element '"+name+"' in query '"+getRel()+"'");
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/TemplateConverterTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java // public class ItemBuilder { // // private List<DataEntry> dataEntries = new LinkedList<>(); // private UriConstructor constructor; // private LinkBuilder linkBuilder; // // public ItemBuilder(URI href) { // constructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public ItemBuilder addData(DataEntry entry) { // dataEntries.add(entry); // return this; // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public Item build() { // return new Item(constructor.getBase(), dataEntries, linkBuilder.build()); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/TemplateBuilder.java // public class TemplateBuilder { // private List<DataEntry> entries = new LinkedList<>(); // // public TemplateBuilder filledFromItem(Item item) { // setEntries(item.getData()); // return this; // } // // private void setEntries(List<DataEntry> entries) { // this.entries.clear(); // this.entries.addAll(entries); // } // // public TemplateBuilder emptyFromItem(Item item) { // List<DataEntry> itemEntries = getClearedDataEntries(item); // setEntries(itemEntries); // // return this; // } // // private List<DataEntry> getClearedDataEntries(Item item) { // List<DataEntry> itemEntries = item.getData(); // List<DataEntry> clearedDataEntreis = new LinkedList<>(); // for(DataEntry entry : itemEntries) { // clearedDataEntreis.add(DataEntryFactory.createEmpty(entry.getName())); // } // return clearedDataEntreis; // } // // // public TemplateBuilder emptyWithNames(String ... names) { // List<DataEntry> nameEntries = new LinkedList<>(); // for(String name : names) { // nameEntries.add(DataEntryFactory.createEmpty(name)); // } // setEntries(nameEntries); // return this; // } // // public Template build() { // return new Template(entries); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // }
import de.fesere.hypermedia.cj.model.builder.ItemBuilder; import de.fesere.hypermedia.cj.model.builder.TemplateBuilder; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import org.junit.Test; import java.net.URI; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat;
package de.fesere.hypermedia.cj.model; public class TemplateConverterTest { @Test public void test_convertingFromFilledTemplateToDomain() {
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java // public class ItemBuilder { // // private List<DataEntry> dataEntries = new LinkedList<>(); // private UriConstructor constructor; // private LinkBuilder linkBuilder; // // public ItemBuilder(URI href) { // constructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public ItemBuilder addData(DataEntry entry) { // dataEntries.add(entry); // return this; // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public Item build() { // return new Item(constructor.getBase(), dataEntries, linkBuilder.build()); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/TemplateBuilder.java // public class TemplateBuilder { // private List<DataEntry> entries = new LinkedList<>(); // // public TemplateBuilder filledFromItem(Item item) { // setEntries(item.getData()); // return this; // } // // private void setEntries(List<DataEntry> entries) { // this.entries.clear(); // this.entries.addAll(entries); // } // // public TemplateBuilder emptyFromItem(Item item) { // List<DataEntry> itemEntries = getClearedDataEntries(item); // setEntries(itemEntries); // // return this; // } // // private List<DataEntry> getClearedDataEntries(Item item) { // List<DataEntry> itemEntries = item.getData(); // List<DataEntry> clearedDataEntreis = new LinkedList<>(); // for(DataEntry entry : itemEntries) { // clearedDataEntreis.add(DataEntryFactory.createEmpty(entry.getName())); // } // return clearedDataEntreis; // } // // // public TemplateBuilder emptyWithNames(String ... names) { // List<DataEntry> nameEntries = new LinkedList<>(); // for(String name : names) { // nameEntries.add(DataEntryFactory.createEmpty(name)); // } // setEntries(nameEntries); // return this; // } // // public Template build() { // return new Template(entries); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // Path: src/test/java/de/fesere/hypermedia/cj/model/TemplateConverterTest.java import de.fesere.hypermedia.cj.model.builder.ItemBuilder; import de.fesere.hypermedia.cj.model.builder.TemplateBuilder; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import org.junit.Test; import java.net.URI; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; package de.fesere.hypermedia.cj.model; public class TemplateConverterTest { @Test public void test_convertingFromFilledTemplateToDomain() {
Item item = new ItemBuilder(URI.create("http://foo.com")).addData(create("name", "Felipe", "Users name")).addData(new NumberDataEntry("age", 24, "Users age")).build();
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/TemplateConverterTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java // public class ItemBuilder { // // private List<DataEntry> dataEntries = new LinkedList<>(); // private UriConstructor constructor; // private LinkBuilder linkBuilder; // // public ItemBuilder(URI href) { // constructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public ItemBuilder addData(DataEntry entry) { // dataEntries.add(entry); // return this; // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public Item build() { // return new Item(constructor.getBase(), dataEntries, linkBuilder.build()); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/TemplateBuilder.java // public class TemplateBuilder { // private List<DataEntry> entries = new LinkedList<>(); // // public TemplateBuilder filledFromItem(Item item) { // setEntries(item.getData()); // return this; // } // // private void setEntries(List<DataEntry> entries) { // this.entries.clear(); // this.entries.addAll(entries); // } // // public TemplateBuilder emptyFromItem(Item item) { // List<DataEntry> itemEntries = getClearedDataEntries(item); // setEntries(itemEntries); // // return this; // } // // private List<DataEntry> getClearedDataEntries(Item item) { // List<DataEntry> itemEntries = item.getData(); // List<DataEntry> clearedDataEntreis = new LinkedList<>(); // for(DataEntry entry : itemEntries) { // clearedDataEntreis.add(DataEntryFactory.createEmpty(entry.getName())); // } // return clearedDataEntreis; // } // // // public TemplateBuilder emptyWithNames(String ... names) { // List<DataEntry> nameEntries = new LinkedList<>(); // for(String name : names) { // nameEntries.add(DataEntryFactory.createEmpty(name)); // } // setEntries(nameEntries); // return this; // } // // public Template build() { // return new Template(entries); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // }
import de.fesere.hypermedia.cj.model.builder.ItemBuilder; import de.fesere.hypermedia.cj.model.builder.TemplateBuilder; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import org.junit.Test; import java.net.URI; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat;
package de.fesere.hypermedia.cj.model; public class TemplateConverterTest { @Test public void test_convertingFromFilledTemplateToDomain() {
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java // public class ItemBuilder { // // private List<DataEntry> dataEntries = new LinkedList<>(); // private UriConstructor constructor; // private LinkBuilder linkBuilder; // // public ItemBuilder(URI href) { // constructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public ItemBuilder addData(DataEntry entry) { // dataEntries.add(entry); // return this; // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public Item build() { // return new Item(constructor.getBase(), dataEntries, linkBuilder.build()); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/TemplateBuilder.java // public class TemplateBuilder { // private List<DataEntry> entries = new LinkedList<>(); // // public TemplateBuilder filledFromItem(Item item) { // setEntries(item.getData()); // return this; // } // // private void setEntries(List<DataEntry> entries) { // this.entries.clear(); // this.entries.addAll(entries); // } // // public TemplateBuilder emptyFromItem(Item item) { // List<DataEntry> itemEntries = getClearedDataEntries(item); // setEntries(itemEntries); // // return this; // } // // private List<DataEntry> getClearedDataEntries(Item item) { // List<DataEntry> itemEntries = item.getData(); // List<DataEntry> clearedDataEntreis = new LinkedList<>(); // for(DataEntry entry : itemEntries) { // clearedDataEntreis.add(DataEntryFactory.createEmpty(entry.getName())); // } // return clearedDataEntreis; // } // // // public TemplateBuilder emptyWithNames(String ... names) { // List<DataEntry> nameEntries = new LinkedList<>(); // for(String name : names) { // nameEntries.add(DataEntryFactory.createEmpty(name)); // } // setEntries(nameEntries); // return this; // } // // public Template build() { // return new Template(entries); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // Path: src/test/java/de/fesere/hypermedia/cj/model/TemplateConverterTest.java import de.fesere.hypermedia.cj.model.builder.ItemBuilder; import de.fesere.hypermedia.cj.model.builder.TemplateBuilder; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import org.junit.Test; import java.net.URI; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; package de.fesere.hypermedia.cj.model; public class TemplateConverterTest { @Test public void test_convertingFromFilledTemplateToDomain() {
Item item = new ItemBuilder(URI.create("http://foo.com")).addData(create("name", "Felipe", "Users name")).addData(new NumberDataEntry("age", 24, "Users age")).build();
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/TemplateConverterTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java // public class ItemBuilder { // // private List<DataEntry> dataEntries = new LinkedList<>(); // private UriConstructor constructor; // private LinkBuilder linkBuilder; // // public ItemBuilder(URI href) { // constructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public ItemBuilder addData(DataEntry entry) { // dataEntries.add(entry); // return this; // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public Item build() { // return new Item(constructor.getBase(), dataEntries, linkBuilder.build()); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/TemplateBuilder.java // public class TemplateBuilder { // private List<DataEntry> entries = new LinkedList<>(); // // public TemplateBuilder filledFromItem(Item item) { // setEntries(item.getData()); // return this; // } // // private void setEntries(List<DataEntry> entries) { // this.entries.clear(); // this.entries.addAll(entries); // } // // public TemplateBuilder emptyFromItem(Item item) { // List<DataEntry> itemEntries = getClearedDataEntries(item); // setEntries(itemEntries); // // return this; // } // // private List<DataEntry> getClearedDataEntries(Item item) { // List<DataEntry> itemEntries = item.getData(); // List<DataEntry> clearedDataEntreis = new LinkedList<>(); // for(DataEntry entry : itemEntries) { // clearedDataEntreis.add(DataEntryFactory.createEmpty(entry.getName())); // } // return clearedDataEntreis; // } // // // public TemplateBuilder emptyWithNames(String ... names) { // List<DataEntry> nameEntries = new LinkedList<>(); // for(String name : names) { // nameEntries.add(DataEntryFactory.createEmpty(name)); // } // setEntries(nameEntries); // return this; // } // // public Template build() { // return new Template(entries); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // }
import de.fesere.hypermedia.cj.model.builder.ItemBuilder; import de.fesere.hypermedia.cj.model.builder.TemplateBuilder; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import org.junit.Test; import java.net.URI; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat;
package de.fesere.hypermedia.cj.model; public class TemplateConverterTest { @Test public void test_convertingFromFilledTemplateToDomain() {
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java // public class ItemBuilder { // // private List<DataEntry> dataEntries = new LinkedList<>(); // private UriConstructor constructor; // private LinkBuilder linkBuilder; // // public ItemBuilder(URI href) { // constructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public ItemBuilder addData(DataEntry entry) { // dataEntries.add(entry); // return this; // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public Item build() { // return new Item(constructor.getBase(), dataEntries, linkBuilder.build()); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/TemplateBuilder.java // public class TemplateBuilder { // private List<DataEntry> entries = new LinkedList<>(); // // public TemplateBuilder filledFromItem(Item item) { // setEntries(item.getData()); // return this; // } // // private void setEntries(List<DataEntry> entries) { // this.entries.clear(); // this.entries.addAll(entries); // } // // public TemplateBuilder emptyFromItem(Item item) { // List<DataEntry> itemEntries = getClearedDataEntries(item); // setEntries(itemEntries); // // return this; // } // // private List<DataEntry> getClearedDataEntries(Item item) { // List<DataEntry> itemEntries = item.getData(); // List<DataEntry> clearedDataEntreis = new LinkedList<>(); // for(DataEntry entry : itemEntries) { // clearedDataEntreis.add(DataEntryFactory.createEmpty(entry.getName())); // } // return clearedDataEntreis; // } // // // public TemplateBuilder emptyWithNames(String ... names) { // List<DataEntry> nameEntries = new LinkedList<>(); // for(String name : names) { // nameEntries.add(DataEntryFactory.createEmpty(name)); // } // setEntries(nameEntries); // return this; // } // // public Template build() { // return new Template(entries); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // Path: src/test/java/de/fesere/hypermedia/cj/model/TemplateConverterTest.java import de.fesere.hypermedia.cj.model.builder.ItemBuilder; import de.fesere.hypermedia.cj.model.builder.TemplateBuilder; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import org.junit.Test; import java.net.URI; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; package de.fesere.hypermedia.cj.model; public class TemplateConverterTest { @Test public void test_convertingFromFilledTemplateToDomain() {
Item item = new ItemBuilder(URI.create("http://foo.com")).addData(create("name", "Felipe", "Users name")).addData(new NumberDataEntry("age", 24, "Users age")).build();
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/TemplateConverterTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java // public class ItemBuilder { // // private List<DataEntry> dataEntries = new LinkedList<>(); // private UriConstructor constructor; // private LinkBuilder linkBuilder; // // public ItemBuilder(URI href) { // constructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public ItemBuilder addData(DataEntry entry) { // dataEntries.add(entry); // return this; // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public Item build() { // return new Item(constructor.getBase(), dataEntries, linkBuilder.build()); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/TemplateBuilder.java // public class TemplateBuilder { // private List<DataEntry> entries = new LinkedList<>(); // // public TemplateBuilder filledFromItem(Item item) { // setEntries(item.getData()); // return this; // } // // private void setEntries(List<DataEntry> entries) { // this.entries.clear(); // this.entries.addAll(entries); // } // // public TemplateBuilder emptyFromItem(Item item) { // List<DataEntry> itemEntries = getClearedDataEntries(item); // setEntries(itemEntries); // // return this; // } // // private List<DataEntry> getClearedDataEntries(Item item) { // List<DataEntry> itemEntries = item.getData(); // List<DataEntry> clearedDataEntreis = new LinkedList<>(); // for(DataEntry entry : itemEntries) { // clearedDataEntreis.add(DataEntryFactory.createEmpty(entry.getName())); // } // return clearedDataEntreis; // } // // // public TemplateBuilder emptyWithNames(String ... names) { // List<DataEntry> nameEntries = new LinkedList<>(); // for(String name : names) { // nameEntries.add(DataEntryFactory.createEmpty(name)); // } // setEntries(nameEntries); // return this; // } // // public Template build() { // return new Template(entries); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // }
import de.fesere.hypermedia.cj.model.builder.ItemBuilder; import de.fesere.hypermedia.cj.model.builder.TemplateBuilder; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import org.junit.Test; import java.net.URI; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat;
package de.fesere.hypermedia.cj.model; public class TemplateConverterTest { @Test public void test_convertingFromFilledTemplateToDomain() { Item item = new ItemBuilder(URI.create("http://foo.com")).addData(create("name", "Felipe", "Users name")).addData(new NumberDataEntry("age", 24, "Users age")).build();
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java // public class ItemBuilder { // // private List<DataEntry> dataEntries = new LinkedList<>(); // private UriConstructor constructor; // private LinkBuilder linkBuilder; // // public ItemBuilder(URI href) { // constructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public ItemBuilder addData(DataEntry entry) { // dataEntries.add(entry); // return this; // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public Item build() { // return new Item(constructor.getBase(), dataEntries, linkBuilder.build()); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/TemplateBuilder.java // public class TemplateBuilder { // private List<DataEntry> entries = new LinkedList<>(); // // public TemplateBuilder filledFromItem(Item item) { // setEntries(item.getData()); // return this; // } // // private void setEntries(List<DataEntry> entries) { // this.entries.clear(); // this.entries.addAll(entries); // } // // public TemplateBuilder emptyFromItem(Item item) { // List<DataEntry> itemEntries = getClearedDataEntries(item); // setEntries(itemEntries); // // return this; // } // // private List<DataEntry> getClearedDataEntries(Item item) { // List<DataEntry> itemEntries = item.getData(); // List<DataEntry> clearedDataEntreis = new LinkedList<>(); // for(DataEntry entry : itemEntries) { // clearedDataEntreis.add(DataEntryFactory.createEmpty(entry.getName())); // } // return clearedDataEntreis; // } // // // public TemplateBuilder emptyWithNames(String ... names) { // List<DataEntry> nameEntries = new LinkedList<>(); // for(String name : names) { // nameEntries.add(DataEntryFactory.createEmpty(name)); // } // setEntries(nameEntries); // return this; // } // // public Template build() { // return new Template(entries); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // Path: src/test/java/de/fesere/hypermedia/cj/model/TemplateConverterTest.java import de.fesere.hypermedia.cj.model.builder.ItemBuilder; import de.fesere.hypermedia.cj.model.builder.TemplateBuilder; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import org.junit.Test; import java.net.URI; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; package de.fesere.hypermedia.cj.model; public class TemplateConverterTest { @Test public void test_convertingFromFilledTemplateToDomain() { Item item = new ItemBuilder(URI.create("http://foo.com")).addData(create("name", "Felipe", "Users name")).addData(new NumberDataEntry("age", 24, "Users age")).build();
Template template = new TemplateBuilder().filledFromItem(item).build();
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/TemplateConverterTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java // public class ItemBuilder { // // private List<DataEntry> dataEntries = new LinkedList<>(); // private UriConstructor constructor; // private LinkBuilder linkBuilder; // // public ItemBuilder(URI href) { // constructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public ItemBuilder addData(DataEntry entry) { // dataEntries.add(entry); // return this; // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public Item build() { // return new Item(constructor.getBase(), dataEntries, linkBuilder.build()); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/TemplateBuilder.java // public class TemplateBuilder { // private List<DataEntry> entries = new LinkedList<>(); // // public TemplateBuilder filledFromItem(Item item) { // setEntries(item.getData()); // return this; // } // // private void setEntries(List<DataEntry> entries) { // this.entries.clear(); // this.entries.addAll(entries); // } // // public TemplateBuilder emptyFromItem(Item item) { // List<DataEntry> itemEntries = getClearedDataEntries(item); // setEntries(itemEntries); // // return this; // } // // private List<DataEntry> getClearedDataEntries(Item item) { // List<DataEntry> itemEntries = item.getData(); // List<DataEntry> clearedDataEntreis = new LinkedList<>(); // for(DataEntry entry : itemEntries) { // clearedDataEntreis.add(DataEntryFactory.createEmpty(entry.getName())); // } // return clearedDataEntreis; // } // // // public TemplateBuilder emptyWithNames(String ... names) { // List<DataEntry> nameEntries = new LinkedList<>(); // for(String name : names) { // nameEntries.add(DataEntryFactory.createEmpty(name)); // } // setEntries(nameEntries); // return this; // } // // public Template build() { // return new Template(entries); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // }
import de.fesere.hypermedia.cj.model.builder.ItemBuilder; import de.fesere.hypermedia.cj.model.builder.TemplateBuilder; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import org.junit.Test; import java.net.URI; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat;
package de.fesere.hypermedia.cj.model; public class TemplateConverterTest { @Test public void test_convertingFromFilledTemplateToDomain() { Item item = new ItemBuilder(URI.create("http://foo.com")).addData(create("name", "Felipe", "Users name")).addData(new NumberDataEntry("age", 24, "Users age")).build(); Template template = new TemplateBuilder().filledFromItem(item).build(); PersonConverter personConverter = new PersonConverter(); Person felipe = template.convert(personConverter); assertThat(felipe.getName(), is("Felipe")); assertThat(felipe.getAge(), is(24)); }
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java // public class ItemBuilder { // // private List<DataEntry> dataEntries = new LinkedList<>(); // private UriConstructor constructor; // private LinkBuilder linkBuilder; // // public ItemBuilder(URI href) { // constructor = new UriConstructor(href); // linkBuilder = new LinkBuilder(href); // } // // public ItemBuilder addData(DataEntry entry) { // dataEntries.add(entry); // return this; // } // // public LinkBuilder getLinkBuilder() { // return linkBuilder; // } // // public Item build() { // return new Item(constructor.getBase(), dataEntries, linkBuilder.build()); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/TemplateBuilder.java // public class TemplateBuilder { // private List<DataEntry> entries = new LinkedList<>(); // // public TemplateBuilder filledFromItem(Item item) { // setEntries(item.getData()); // return this; // } // // private void setEntries(List<DataEntry> entries) { // this.entries.clear(); // this.entries.addAll(entries); // } // // public TemplateBuilder emptyFromItem(Item item) { // List<DataEntry> itemEntries = getClearedDataEntries(item); // setEntries(itemEntries); // // return this; // } // // private List<DataEntry> getClearedDataEntries(Item item) { // List<DataEntry> itemEntries = item.getData(); // List<DataEntry> clearedDataEntreis = new LinkedList<>(); // for(DataEntry entry : itemEntries) { // clearedDataEntreis.add(DataEntryFactory.createEmpty(entry.getName())); // } // return clearedDataEntreis; // } // // // public TemplateBuilder emptyWithNames(String ... names) { // List<DataEntry> nameEntries = new LinkedList<>(); // for(String name : names) { // nameEntries.add(DataEntryFactory.createEmpty(name)); // } // setEntries(nameEntries); // return this; // } // // public Template build() { // return new Template(entries); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // Path: src/test/java/de/fesere/hypermedia/cj/model/TemplateConverterTest.java import de.fesere.hypermedia.cj.model.builder.ItemBuilder; import de.fesere.hypermedia.cj.model.builder.TemplateBuilder; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import org.junit.Test; import java.net.URI; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; package de.fesere.hypermedia.cj.model; public class TemplateConverterTest { @Test public void test_convertingFromFilledTemplateToDomain() { Item item = new ItemBuilder(URI.create("http://foo.com")).addData(create("name", "Felipe", "Users name")).addData(new NumberDataEntry("age", 24, "Users age")).build(); Template template = new TemplateBuilder().filledFromItem(item).build(); PersonConverter personConverter = new PersonConverter(); Person felipe = template.convert(personConverter); assertThat(felipe.getName(), is("Felipe")); assertThat(felipe.getAge(), is(24)); }
private class PersonConverter implements ReadTransformation<Person> {
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/builder/ErrorBuilder.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/Collection.java // @JsonTypeName("collection") // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE) // @JsonPropertyOrder({"version", "href", "links", "error", "items", "queries", "template"}) // public class Collection implements Wrapped{ // // private static final String VERSION = "1.0"; // // @JsonProperty("href") // private final URI href; // // @JsonProperty("items") // private final List<Item> items = new ArrayList<>(); // // @JsonProperty("links") // private final List<Link> links = new ArrayList<>(); // // @JsonProperty("queries") // private final List<Query> queries = new ArrayList<>(); // // @JsonProperty("template") // private Template template; // // @JsonProperty("error") // private Error error; // // // // @JsonCreator() // public Collection(@JsonProperty("href") URI href) { // this.href = href; // } // // public Collection(URI uri, Error error) { // this(uri); // this.error = error; // } // // public Collection(URI href, List<Item> items, List<Query> queries, List<Link>links, Template template) { // this(href); // if(items != null) { // this.items.addAll(items); // } // if(queries != null) { // this.queries.addAll(queries); // } // if(links != null) { // this.links.addAll(links); // } // this.template = template; // } // // public URI getHref() { // return this.href; // } // // public List<Item> getItems() { // throwExceptionOnError(); // // return new ArrayList<>(items); // } // // public List<Link> getLinks() { // throwExceptionOnError(); // // return new ArrayList<>(links); // } // // private void throwExceptionOnError() { // if(hasError()) { // throw new CollectionHasErrorsException(getError()); // } // } // // public List<Query> getQueries() { // throwExceptionOnError(); // // return new ArrayList<>(queries); // } // // // public <T> List<T> transform(ReadTransformation<T> transformer) { // throwExceptionOnError(); // // List<T> result = new ArrayList<>(items.size()); // // for(Item item : items) { // T convertedItem = transformer.transform(item); // if(convertedItem != null) { // result.add(convertedItem); // } // } // // return result; // } // // public boolean hasError() { // return error != null; // } // // public Error getError() { // return error; // } // // public Link getLink(String rel) { // throwExceptionOnError(); // // return findByRel(links,rel); // // // } // // private <T extends Link> T findByRel(List<T> elements, String rel) { // for(T linkable : elements ) { // if(linkable.getRel().equalsIgnoreCase(rel)) { // return linkable; // } // } // // throw new ElementNotFoundException("Did not find element '"+rel+"' in collection " + href ); // } // // public Query getQuery(String rel) { // throwExceptionOnError(); // // return findByRel(queries, rel); // } // // public Template getTemplate() { // throwExceptionOnError(); // return template; // } // // @JsonProperty("version") // public String getVersion() { // return VERSION; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Error.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // public class Error { // // private final String title; // private final String code; // private final String message; // // @JsonCreator // public Error(@JsonProperty("title") String title, @JsonProperty("code") String code, @JsonProperty("message") String message) { // // this.title = title; // this.code = code; // this.message = message; // } // // public String getTitle() { // return title; // } // // public String getMessage() { // return message; // } // // public String getCode() { // return code; // } // }
import de.fesere.hypermedia.cj.model.Collection; import de.fesere.hypermedia.cj.model.Error; import java.net.URI;
package de.fesere.hypermedia.cj.model.builder; public class ErrorBuilder { private String title = "An error occured"; private String status = "500"; private String message = "There was an error processing the message"; private URI base; public ErrorBuilder(URI base) { this.base = base; } public ErrorBuilder withTitle(String title) { this.title = title; return this; } public ErrorBuilder withStatus(String status) { this.status = status; return this; } public ErrorBuilder withMessage(String message) { this.message = message; return this; }
// Path: src/main/java/de/fesere/hypermedia/cj/model/Collection.java // @JsonTypeName("collection") // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE) // @JsonPropertyOrder({"version", "href", "links", "error", "items", "queries", "template"}) // public class Collection implements Wrapped{ // // private static final String VERSION = "1.0"; // // @JsonProperty("href") // private final URI href; // // @JsonProperty("items") // private final List<Item> items = new ArrayList<>(); // // @JsonProperty("links") // private final List<Link> links = new ArrayList<>(); // // @JsonProperty("queries") // private final List<Query> queries = new ArrayList<>(); // // @JsonProperty("template") // private Template template; // // @JsonProperty("error") // private Error error; // // // // @JsonCreator() // public Collection(@JsonProperty("href") URI href) { // this.href = href; // } // // public Collection(URI uri, Error error) { // this(uri); // this.error = error; // } // // public Collection(URI href, List<Item> items, List<Query> queries, List<Link>links, Template template) { // this(href); // if(items != null) { // this.items.addAll(items); // } // if(queries != null) { // this.queries.addAll(queries); // } // if(links != null) { // this.links.addAll(links); // } // this.template = template; // } // // public URI getHref() { // return this.href; // } // // public List<Item> getItems() { // throwExceptionOnError(); // // return new ArrayList<>(items); // } // // public List<Link> getLinks() { // throwExceptionOnError(); // // return new ArrayList<>(links); // } // // private void throwExceptionOnError() { // if(hasError()) { // throw new CollectionHasErrorsException(getError()); // } // } // // public List<Query> getQueries() { // throwExceptionOnError(); // // return new ArrayList<>(queries); // } // // // public <T> List<T> transform(ReadTransformation<T> transformer) { // throwExceptionOnError(); // // List<T> result = new ArrayList<>(items.size()); // // for(Item item : items) { // T convertedItem = transformer.transform(item); // if(convertedItem != null) { // result.add(convertedItem); // } // } // // return result; // } // // public boolean hasError() { // return error != null; // } // // public Error getError() { // return error; // } // // public Link getLink(String rel) { // throwExceptionOnError(); // // return findByRel(links,rel); // // // } // // private <T extends Link> T findByRel(List<T> elements, String rel) { // for(T linkable : elements ) { // if(linkable.getRel().equalsIgnoreCase(rel)) { // return linkable; // } // } // // throw new ElementNotFoundException("Did not find element '"+rel+"' in collection " + href ); // } // // public Query getQuery(String rel) { // throwExceptionOnError(); // // return findByRel(queries, rel); // } // // public Template getTemplate() { // throwExceptionOnError(); // return template; // } // // @JsonProperty("version") // public String getVersion() { // return VERSION; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Error.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // public class Error { // // private final String title; // private final String code; // private final String message; // // @JsonCreator // public Error(@JsonProperty("title") String title, @JsonProperty("code") String code, @JsonProperty("message") String message) { // // this.title = title; // this.code = code; // this.message = message; // } // // public String getTitle() { // return title; // } // // public String getMessage() { // return message; // } // // public String getCode() { // return code; // } // } // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ErrorBuilder.java import de.fesere.hypermedia.cj.model.Collection; import de.fesere.hypermedia.cj.model.Error; import java.net.URI; package de.fesere.hypermedia.cj.model.builder; public class ErrorBuilder { private String title = "An error occured"; private String status = "500"; private String message = "There was an error processing the message"; private URI base; public ErrorBuilder(URI base) { this.base = base; } public ErrorBuilder withTitle(String title) { this.title = title; return this; } public ErrorBuilder withStatus(String status) { this.status = status; return this; } public ErrorBuilder withMessage(String message) { this.message = message; return this; }
public Collection build() {
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/builder/ErrorBuilder.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/Collection.java // @JsonTypeName("collection") // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE) // @JsonPropertyOrder({"version", "href", "links", "error", "items", "queries", "template"}) // public class Collection implements Wrapped{ // // private static final String VERSION = "1.0"; // // @JsonProperty("href") // private final URI href; // // @JsonProperty("items") // private final List<Item> items = new ArrayList<>(); // // @JsonProperty("links") // private final List<Link> links = new ArrayList<>(); // // @JsonProperty("queries") // private final List<Query> queries = new ArrayList<>(); // // @JsonProperty("template") // private Template template; // // @JsonProperty("error") // private Error error; // // // // @JsonCreator() // public Collection(@JsonProperty("href") URI href) { // this.href = href; // } // // public Collection(URI uri, Error error) { // this(uri); // this.error = error; // } // // public Collection(URI href, List<Item> items, List<Query> queries, List<Link>links, Template template) { // this(href); // if(items != null) { // this.items.addAll(items); // } // if(queries != null) { // this.queries.addAll(queries); // } // if(links != null) { // this.links.addAll(links); // } // this.template = template; // } // // public URI getHref() { // return this.href; // } // // public List<Item> getItems() { // throwExceptionOnError(); // // return new ArrayList<>(items); // } // // public List<Link> getLinks() { // throwExceptionOnError(); // // return new ArrayList<>(links); // } // // private void throwExceptionOnError() { // if(hasError()) { // throw new CollectionHasErrorsException(getError()); // } // } // // public List<Query> getQueries() { // throwExceptionOnError(); // // return new ArrayList<>(queries); // } // // // public <T> List<T> transform(ReadTransformation<T> transformer) { // throwExceptionOnError(); // // List<T> result = new ArrayList<>(items.size()); // // for(Item item : items) { // T convertedItem = transformer.transform(item); // if(convertedItem != null) { // result.add(convertedItem); // } // } // // return result; // } // // public boolean hasError() { // return error != null; // } // // public Error getError() { // return error; // } // // public Link getLink(String rel) { // throwExceptionOnError(); // // return findByRel(links,rel); // // // } // // private <T extends Link> T findByRel(List<T> elements, String rel) { // for(T linkable : elements ) { // if(linkable.getRel().equalsIgnoreCase(rel)) { // return linkable; // } // } // // throw new ElementNotFoundException("Did not find element '"+rel+"' in collection " + href ); // } // // public Query getQuery(String rel) { // throwExceptionOnError(); // // return findByRel(queries, rel); // } // // public Template getTemplate() { // throwExceptionOnError(); // return template; // } // // @JsonProperty("version") // public String getVersion() { // return VERSION; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Error.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // public class Error { // // private final String title; // private final String code; // private final String message; // // @JsonCreator // public Error(@JsonProperty("title") String title, @JsonProperty("code") String code, @JsonProperty("message") String message) { // // this.title = title; // this.code = code; // this.message = message; // } // // public String getTitle() { // return title; // } // // public String getMessage() { // return message; // } // // public String getCode() { // return code; // } // }
import de.fesere.hypermedia.cj.model.Collection; import de.fesere.hypermedia.cj.model.Error; import java.net.URI;
package de.fesere.hypermedia.cj.model.builder; public class ErrorBuilder { private String title = "An error occured"; private String status = "500"; private String message = "There was an error processing the message"; private URI base; public ErrorBuilder(URI base) { this.base = base; } public ErrorBuilder withTitle(String title) { this.title = title; return this; } public ErrorBuilder withStatus(String status) { this.status = status; return this; } public ErrorBuilder withMessage(String message) { this.message = message; return this; } public Collection build() {
// Path: src/main/java/de/fesere/hypermedia/cj/model/Collection.java // @JsonTypeName("collection") // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE) // @JsonPropertyOrder({"version", "href", "links", "error", "items", "queries", "template"}) // public class Collection implements Wrapped{ // // private static final String VERSION = "1.0"; // // @JsonProperty("href") // private final URI href; // // @JsonProperty("items") // private final List<Item> items = new ArrayList<>(); // // @JsonProperty("links") // private final List<Link> links = new ArrayList<>(); // // @JsonProperty("queries") // private final List<Query> queries = new ArrayList<>(); // // @JsonProperty("template") // private Template template; // // @JsonProperty("error") // private Error error; // // // // @JsonCreator() // public Collection(@JsonProperty("href") URI href) { // this.href = href; // } // // public Collection(URI uri, Error error) { // this(uri); // this.error = error; // } // // public Collection(URI href, List<Item> items, List<Query> queries, List<Link>links, Template template) { // this(href); // if(items != null) { // this.items.addAll(items); // } // if(queries != null) { // this.queries.addAll(queries); // } // if(links != null) { // this.links.addAll(links); // } // this.template = template; // } // // public URI getHref() { // return this.href; // } // // public List<Item> getItems() { // throwExceptionOnError(); // // return new ArrayList<>(items); // } // // public List<Link> getLinks() { // throwExceptionOnError(); // // return new ArrayList<>(links); // } // // private void throwExceptionOnError() { // if(hasError()) { // throw new CollectionHasErrorsException(getError()); // } // } // // public List<Query> getQueries() { // throwExceptionOnError(); // // return new ArrayList<>(queries); // } // // // public <T> List<T> transform(ReadTransformation<T> transformer) { // throwExceptionOnError(); // // List<T> result = new ArrayList<>(items.size()); // // for(Item item : items) { // T convertedItem = transformer.transform(item); // if(convertedItem != null) { // result.add(convertedItem); // } // } // // return result; // } // // public boolean hasError() { // return error != null; // } // // public Error getError() { // return error; // } // // public Link getLink(String rel) { // throwExceptionOnError(); // // return findByRel(links,rel); // // // } // // private <T extends Link> T findByRel(List<T> elements, String rel) { // for(T linkable : elements ) { // if(linkable.getRel().equalsIgnoreCase(rel)) { // return linkable; // } // } // // throw new ElementNotFoundException("Did not find element '"+rel+"' in collection " + href ); // } // // public Query getQuery(String rel) { // throwExceptionOnError(); // // return findByRel(queries, rel); // } // // public Template getTemplate() { // throwExceptionOnError(); // return template; // } // // @JsonProperty("version") // public String getVersion() { // return VERSION; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Error.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // public class Error { // // private final String title; // private final String code; // private final String message; // // @JsonCreator // public Error(@JsonProperty("title") String title, @JsonProperty("code") String code, @JsonProperty("message") String message) { // // this.title = title; // this.code = code; // this.message = message; // } // // public String getTitle() { // return title; // } // // public String getMessage() { // return message; // } // // public String getCode() { // return code; // } // } // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ErrorBuilder.java import de.fesere.hypermedia.cj.model.Collection; import de.fesere.hypermedia.cj.model.Error; import java.net.URI; package de.fesere.hypermedia.cj.model.builder; public class ErrorBuilder { private String title = "An error occured"; private String status = "500"; private String message = "There was an error processing the message"; private URI base; public ErrorBuilder(URI base) { this.base = base; } public ErrorBuilder withTitle(String title) { this.title = title; return this; } public ErrorBuilder withStatus(String status) { this.status = status; return this; } public ErrorBuilder withMessage(String message) { this.message = message; return this; } public Collection build() {
Error error = new Error(title, "" + status, message);
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonPropertyOrder({"href", "data", "links"}) // public class Item { // private final URI href; // private final List<DataEntry> data = new ArrayList<>(); // private List<Link> links = new ArrayList<>(); // // // public Item() { // this(Collections.<DataEntry>emptyList()); // } // // public Item(List<DataEntry> data) { // this((URI) null); // if (data != null) { // this.data.addAll(data); // } // } // // public Item(URI href) { // this(href, Collections.<Link>emptyList()); // } // // @JsonCreator // public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { // this.href = href; // this.links = links; // } // // public Item(URI href, List<DataEntry> entries, List<Link> links) { // this(href, links); // this.data.addAll(entries); // } // // public URI getHref() { // return this.href; // } // // public void addData(DataEntry dataEntry) { // data.add(dataEntry); // } // // public List<DataEntry> getData() { // return new ArrayList<>(data); // } // // public List<Link> getLinks() { // return links; // } // // public String getString(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof StringDataEntry) { // return ((StringDataEntry) found).getValue(); // } // throw new PropertyNotFoundException(name, href, String.class); // } // // public boolean isNullValue(String name) { // DataEntry found = findDataEntry(name); // // return found instanceof NullDataEntry; // } // // public int getInt(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Integer.parseInt(value.toString()); // // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public double getDouble(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Double.parseDouble(value.toString()); // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public boolean getBoolean(String name) { // DataEntry entry = findDataEntry(name); // if (entry instanceof BooleanDataEntry) { // return (boolean) entry.getValue(); // } // // throw new PropertyNotFoundException(name, href, Boolean.class); // } // // private DataEntry findDataEntry(String name) { // DataEntry found = null; // for (DataEntry entry : data) { // if (entry.getName().equals(name)) { // found = entry; // break; // } // } // if (found == null) { // throw new ElementNotFoundException("Did not find property '" + name + "' in '" + href + "'"); // } // return found; // } // // public Map<String, Object> extractDataMap() { // Map<String, Object> result = new HashMap<>(); // for (DataEntry entry : data) { // result.put(entry.getName(), entry.getValue()); // } // // return result; // } // // public Object getObject(String entryName) { // DataEntry entry = findDataEntry(entryName); // // return entry.getValue(); // } // }
import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.Item; import java.net.URI; import java.util.LinkedList; import java.util.List;
package de.fesere.hypermedia.cj.model.builder; public class ItemBuilder { private List<DataEntry> dataEntries = new LinkedList<>(); private UriConstructor constructor; private LinkBuilder linkBuilder; public ItemBuilder(URI href) { constructor = new UriConstructor(href); linkBuilder = new LinkBuilder(href); } public ItemBuilder addData(DataEntry entry) { dataEntries.add(entry); return this; } public LinkBuilder getLinkBuilder() { return linkBuilder; }
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonPropertyOrder({"href", "data", "links"}) // public class Item { // private final URI href; // private final List<DataEntry> data = new ArrayList<>(); // private List<Link> links = new ArrayList<>(); // // // public Item() { // this(Collections.<DataEntry>emptyList()); // } // // public Item(List<DataEntry> data) { // this((URI) null); // if (data != null) { // this.data.addAll(data); // } // } // // public Item(URI href) { // this(href, Collections.<Link>emptyList()); // } // // @JsonCreator // public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { // this.href = href; // this.links = links; // } // // public Item(URI href, List<DataEntry> entries, List<Link> links) { // this(href, links); // this.data.addAll(entries); // } // // public URI getHref() { // return this.href; // } // // public void addData(DataEntry dataEntry) { // data.add(dataEntry); // } // // public List<DataEntry> getData() { // return new ArrayList<>(data); // } // // public List<Link> getLinks() { // return links; // } // // public String getString(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof StringDataEntry) { // return ((StringDataEntry) found).getValue(); // } // throw new PropertyNotFoundException(name, href, String.class); // } // // public boolean isNullValue(String name) { // DataEntry found = findDataEntry(name); // // return found instanceof NullDataEntry; // } // // public int getInt(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Integer.parseInt(value.toString()); // // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public double getDouble(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Double.parseDouble(value.toString()); // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public boolean getBoolean(String name) { // DataEntry entry = findDataEntry(name); // if (entry instanceof BooleanDataEntry) { // return (boolean) entry.getValue(); // } // // throw new PropertyNotFoundException(name, href, Boolean.class); // } // // private DataEntry findDataEntry(String name) { // DataEntry found = null; // for (DataEntry entry : data) { // if (entry.getName().equals(name)) { // found = entry; // break; // } // } // if (found == null) { // throw new ElementNotFoundException("Did not find property '" + name + "' in '" + href + "'"); // } // return found; // } // // public Map<String, Object> extractDataMap() { // Map<String, Object> result = new HashMap<>(); // for (DataEntry entry : data) { // result.put(entry.getName(), entry.getValue()); // } // // return result; // } // // public Object getObject(String entryName) { // DataEntry entry = findDataEntry(entryName); // // return entry.getValue(); // } // } // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/ItemBuilder.java import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.Item; import java.net.URI; import java.util.LinkedList; import java.util.List; package de.fesere.hypermedia.cj.model.builder; public class ItemBuilder { private List<DataEntry> dataEntries = new LinkedList<>(); private UriConstructor constructor; private LinkBuilder linkBuilder; public ItemBuilder(URI href) { constructor = new UriConstructor(href); linkBuilder = new LinkBuilder(href); } public ItemBuilder addData(DataEntry entry) { dataEntries.add(entry); return this; } public LinkBuilder getLinkBuilder() { return linkBuilder; }
public Item build() {
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Template.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/DataEntryTransformer.java // public class DataEntryTransformer<T> implements ReadTransformation<T> { // // // private ReadTransformation<T> innerTransformer; // // public DataEntryTransformer(ReadTransformation<T> innerTransformer) { // this.innerTransformer = innerTransformer; // } // // // public T transform(List<DataEntry> dataEntryList) { // Item item = new Item(dataEntryList); // return transform(item); // } // // @Override // public T transform(Item item) { // return innerTransformer.transform(item) ; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // }
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.DataEntryTransformer; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map;
package de.fesere.hypermedia.cj.model; @JsonTypeName("template") @JsonIgnoreProperties(ignoreUnknown = true)
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/DataEntryTransformer.java // public class DataEntryTransformer<T> implements ReadTransformation<T> { // // // private ReadTransformation<T> innerTransformer; // // public DataEntryTransformer(ReadTransformation<T> innerTransformer) { // this.innerTransformer = innerTransformer; // } // // // public T transform(List<DataEntry> dataEntryList) { // Item item = new Item(dataEntryList); // return transform(item); // } // // @Override // public T transform(Item item) { // return innerTransformer.transform(item) ; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Template.java import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.DataEntryTransformer; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; package de.fesere.hypermedia.cj.model; @JsonTypeName("template") @JsonIgnoreProperties(ignoreUnknown = true)
public class Template implements Wrapped {
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Template.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/DataEntryTransformer.java // public class DataEntryTransformer<T> implements ReadTransformation<T> { // // // private ReadTransformation<T> innerTransformer; // // public DataEntryTransformer(ReadTransformation<T> innerTransformer) { // this.innerTransformer = innerTransformer; // } // // // public T transform(List<DataEntry> dataEntryList) { // Item item = new Item(dataEntryList); // return transform(item); // } // // @Override // public T transform(Item item) { // return innerTransformer.transform(item) ; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // }
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.DataEntryTransformer; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map;
package de.fesere.hypermedia.cj.model; @JsonTypeName("template") @JsonIgnoreProperties(ignoreUnknown = true) public class Template implements Wrapped { private List<DataEntry> data; public Template(@JsonProperty("data") List<DataEntry> data) { this.data = data; } public List<DataEntry> getData() { return new LinkedList<>(data); } public void fill(Item item) { List<DataEntry> filledDataEntries = new LinkedList<>(); for(DataEntry entry : data) { String name = entry.getName(); String prompt = entry.getPrompt(); Object value = item.getObject(name);
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/DataEntryTransformer.java // public class DataEntryTransformer<T> implements ReadTransformation<T> { // // // private ReadTransformation<T> innerTransformer; // // public DataEntryTransformer(ReadTransformation<T> innerTransformer) { // this.innerTransformer = innerTransformer; // } // // // public T transform(List<DataEntry> dataEntryList) { // Item item = new Item(dataEntryList); // return transform(item); // } // // @Override // public T transform(Item item) { // return innerTransformer.transform(item) ; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Template.java import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.DataEntryTransformer; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; package de.fesere.hypermedia.cj.model; @JsonTypeName("template") @JsonIgnoreProperties(ignoreUnknown = true) public class Template implements Wrapped { private List<DataEntry> data; public Template(@JsonProperty("data") List<DataEntry> data) { this.data = data; } public List<DataEntry> getData() { return new LinkedList<>(data); } public void fill(Item item) { List<DataEntry> filledDataEntries = new LinkedList<>(); for(DataEntry entry : data) { String name = entry.getName(); String prompt = entry.getPrompt(); Object value = item.getObject(name);
DataEntry filled = DataEntryFactory.create(name, value, prompt);
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Template.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/DataEntryTransformer.java // public class DataEntryTransformer<T> implements ReadTransformation<T> { // // // private ReadTransformation<T> innerTransformer; // // public DataEntryTransformer(ReadTransformation<T> innerTransformer) { // this.innerTransformer = innerTransformer; // } // // // public T transform(List<DataEntry> dataEntryList) { // Item item = new Item(dataEntryList); // return transform(item); // } // // @Override // public T transform(Item item) { // return innerTransformer.transform(item) ; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // }
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.DataEntryTransformer; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map;
package de.fesere.hypermedia.cj.model; @JsonTypeName("template") @JsonIgnoreProperties(ignoreUnknown = true) public class Template implements Wrapped { private List<DataEntry> data; public Template(@JsonProperty("data") List<DataEntry> data) { this.data = data; } public List<DataEntry> getData() { return new LinkedList<>(data); } public void fill(Item item) { List<DataEntry> filledDataEntries = new LinkedList<>(); for(DataEntry entry : data) { String name = entry.getName(); String prompt = entry.getPrompt(); Object value = item.getObject(name); DataEntry filled = DataEntryFactory.create(name, value, prompt); filledDataEntries.add(filled); } this.data = filledDataEntries; }
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/DataEntryTransformer.java // public class DataEntryTransformer<T> implements ReadTransformation<T> { // // // private ReadTransformation<T> innerTransformer; // // public DataEntryTransformer(ReadTransformation<T> innerTransformer) { // this.innerTransformer = innerTransformer; // } // // // public T transform(List<DataEntry> dataEntryList) { // Item item = new Item(dataEntryList); // return transform(item); // } // // @Override // public T transform(Item item) { // return innerTransformer.transform(item) ; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Template.java import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.DataEntryTransformer; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; package de.fesere.hypermedia.cj.model; @JsonTypeName("template") @JsonIgnoreProperties(ignoreUnknown = true) public class Template implements Wrapped { private List<DataEntry> data; public Template(@JsonProperty("data") List<DataEntry> data) { this.data = data; } public List<DataEntry> getData() { return new LinkedList<>(data); } public void fill(Item item) { List<DataEntry> filledDataEntries = new LinkedList<>(); for(DataEntry entry : data) { String name = entry.getName(); String prompt = entry.getPrompt(); Object value = item.getObject(name); DataEntry filled = DataEntryFactory.create(name, value, prompt); filledDataEntries.add(filled); } this.data = filledDataEntries; }
public <T> T convert(ReadTransformation<T> transformation) {
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Template.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/DataEntryTransformer.java // public class DataEntryTransformer<T> implements ReadTransformation<T> { // // // private ReadTransformation<T> innerTransformer; // // public DataEntryTransformer(ReadTransformation<T> innerTransformer) { // this.innerTransformer = innerTransformer; // } // // // public T transform(List<DataEntry> dataEntryList) { // Item item = new Item(dataEntryList); // return transform(item); // } // // @Override // public T transform(Item item) { // return innerTransformer.transform(item) ; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // }
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.DataEntryTransformer; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map;
package de.fesere.hypermedia.cj.model; @JsonTypeName("template") @JsonIgnoreProperties(ignoreUnknown = true) public class Template implements Wrapped { private List<DataEntry> data; public Template(@JsonProperty("data") List<DataEntry> data) { this.data = data; } public List<DataEntry> getData() { return new LinkedList<>(data); } public void fill(Item item) { List<DataEntry> filledDataEntries = new LinkedList<>(); for(DataEntry entry : data) { String name = entry.getName(); String prompt = entry.getPrompt(); Object value = item.getObject(name); DataEntry filled = DataEntryFactory.create(name, value, prompt); filledDataEntries.add(filled); } this.data = filledDataEntries; } public <T> T convert(ReadTransformation<T> transformation) {
// Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public final class DataEntryFactory { // // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // // public static DataEntry create(String name, Object value) { // return create(name, value, null); // } // // private static DataEntry createNone() { // return new NoneDataEntry("none"); // } // // public static DataEntry createNull(String name, String prompt) { // return new NullDataEntry(name,prompt); // } // // public static DataEntry createNull(String name) { // return createNull(name, null); // } // // public static DataEntry createEmpty(String name, String prompt) { // return new StringDataEntry(name, "", prompt); // } // // public static DataEntry createEmpty(String name) { // return new StringDataEntry(name); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/DataEntryTransformer.java // public class DataEntryTransformer<T> implements ReadTransformation<T> { // // // private ReadTransformation<T> innerTransformer; // // public DataEntryTransformer(ReadTransformation<T> innerTransformer) { // this.innerTransformer = innerTransformer; // } // // // public T transform(List<DataEntry> dataEntryList) { // Item item = new Item(dataEntryList); // return transform(item); // } // // @Override // public T transform(Item item) { // return innerTransformer.transform(item) ; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Template.java import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import de.fesere.hypermedia.cj.model.builder.DataEntryFactory; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.DataEntryTransformer; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; package de.fesere.hypermedia.cj.model; @JsonTypeName("template") @JsonIgnoreProperties(ignoreUnknown = true) public class Template implements Wrapped { private List<DataEntry> data; public Template(@JsonProperty("data") List<DataEntry> data) { this.data = data; } public List<DataEntry> getData() { return new LinkedList<>(data); } public void fill(Item item) { List<DataEntry> filledDataEntries = new LinkedList<>(); for(DataEntry entry : data) { String name = entry.getName(); String prompt = entry.getPrompt(); Object value = item.getObject(name); DataEntry filled = DataEntryFactory.create(name, value, prompt); filledDataEntries.add(filled); } this.data = filledDataEntries; } public <T> T convert(ReadTransformation<T> transformation) {
DataEntryTransformer<T> dataEntryTransformer = new DataEntryTransformer<>(transformation);
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/builder/CollectionBuilderTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/transformer/WriteTransformer.java // public interface WriteTransformer<T> { // // Item transform(T input); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // }
import de.fesere.hypermedia.cj.model.*; import de.fesere.hypermedia.cj.transformer.WriteTransformer; import org.junit.Test; import java.net.URI; import java.util.Arrays; import java.util.List; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create;
Person person = new Person("jdoe", "J. Doe", "jdoe@example.org"); Collection collection = new CollectionBuilder<>(href, transformer).addObject(person).build(); assertCollectionSerialization(expected, collection); } @Test public void test_addSingleItemWithLinks() { String expected = readFile("/examples/builder/single-item-with-links.json"); PersonTransformerWithLinks transformer = new PersonTransformerWithLinks(URI.create("http://example.org")); Person person = new Person("jdoe", "J. Doe", "jdoe@example.org"); Collection collection = new CollectionBuilder<>(href, transformer).addObject(person).build(); assertCollectionSerialization(expected, collection); } private class Person { private String id; private final String fullName; private final String email; public Person(String id, String fullName, String email) { this.id = id; this.fullName = fullName; this.email = email; } }
// Path: src/main/java/de/fesere/hypermedia/cj/transformer/WriteTransformer.java // public interface WriteTransformer<T> { // // Item transform(T input); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java // public static DataEntry create(String name, Object value, String prompt) { // // if(StringUtils.isBlank(name)){ // return createNone(); // } // // if(value == null) { // throw new MalformedDataValueException("value of '"+name+"' can not be null"); // } // // Class type = value.getClass(); // // if (TypeUtils.isString(type)) { // return new StringDataEntry(name, (String) value, prompt); // } else if (TypeUtils.isNumber(type)) { // return new NumberDataEntry(name, (Number) value, prompt); // } else if (TypeUtils.isBoolean(type)) { // return new BooleanDataEntry(name, (Boolean) value, prompt); // } else { // throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry"); // } // } // Path: src/test/java/de/fesere/hypermedia/cj/model/builder/CollectionBuilderTest.java import de.fesere.hypermedia.cj.model.*; import de.fesere.hypermedia.cj.transformer.WriteTransformer; import org.junit.Test; import java.net.URI; import java.util.Arrays; import java.util.List; import static de.fesere.hypermedia.cj.model.builder.DataEntryFactory.create; Person person = new Person("jdoe", "J. Doe", "jdoe@example.org"); Collection collection = new CollectionBuilder<>(href, transformer).addObject(person).build(); assertCollectionSerialization(expected, collection); } @Test public void test_addSingleItemWithLinks() { String expected = readFile("/examples/builder/single-item-with-links.json"); PersonTransformerWithLinks transformer = new PersonTransformerWithLinks(URI.create("http://example.org")); Person person = new Person("jdoe", "J. Doe", "jdoe@example.org"); Collection collection = new CollectionBuilder<>(href, transformer).addObject(person).build(); assertCollectionSerialization(expected, collection); } private class Person { private String id; private final String fullName; private final String email; public Person(String id, String fullName, String email) { this.id = id; this.fullName = fullName; this.email = email; } }
private class PersonTransformerWithLinks implements WriteTransformer<Person> {
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/CjClient.java
// Path: src/main/java/de/fesere/hypermedia/cj/http/HTTPClient.java // public interface HTTPClient { // // String getLink(URI uri); // // URI post(URI href, String body, Map<String, String> header); // // String put(URI href, String body, Map<String, String> headder); // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Serializer.java // public class Serializer { // // private final ObjectMapper mapper; // // public Serializer() { // this(new ObjectMapperConfig().getConfiguredObjectMapper()); // } // // protected Serializer(ObjectMapper mapper) { // this.mapper = mapper; // } // // public <T> T deserialize(String input, Class<T> responseClass) { // if(Wrapped.class.isAssignableFrom(responseClass)) { // Object deserializedObject = deserializeWrapped(input); // // if(deserializedObject.getClass().isAssignableFrom(responseClass)) { // return responseClass.cast(deserializedObject); // } // else { // throw new SerializationException("input could not be serialized to " + responseClass.getCanonicalName()); // } // } // // return defaultDeserialisation(input, responseClass); // } // // private Object deserializeWrapped(String input) { // return defaultDeserialisation(input, Wrapper.class).getElement(); // } // // // public String serialize(Object obj) { // if(obj instanceof Wrapped) { // return serialize((Wrapped) obj); // } // // return defaultSerialization(obj); // } // // private String defaultSerialization(Object obj) { // try { // return mapper.writeValueAsString(obj); // } catch (JsonProcessingException e) { // throw new SerializationException("Could not serilize " + obj.getClass().getName() + " to string", e); // } // } // // private String serialize(Wrapped wrapped) { // return defaultSerialization(new Wrapper<>(wrapped)); // } // // private <T> T defaultDeserialisation(String input, Class<T> responseClass) { // try { // return mapper.readValue(input, responseClass); // } catch (IOException e) { // throw new SerializationException("Could not deseriliaze input to " + responseClass.getName(), e); // } // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapper.java // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonSerialize(using = WrapperSerializer.class) // @JsonDeserialize(using = WrapperDeserializer.class) // public class Wrapper<T> { // // private T element; // // // public Wrapper(T element) { // this.element = element; // } // // public T getElement() { // return element; // } // }
import de.fesere.hypermedia.cj.http.HTTPClient; import de.fesere.hypermedia.cj.serialization.Serializer; import de.fesere.hypermedia.cj.serialization.Wrapper; import java.net.URI; import java.util.HashMap; import java.util.Map;
package de.fesere.hypermedia.cj.model; public class CjClient { private final HTTPClient httpClient;
// Path: src/main/java/de/fesere/hypermedia/cj/http/HTTPClient.java // public interface HTTPClient { // // String getLink(URI uri); // // URI post(URI href, String body, Map<String, String> header); // // String put(URI href, String body, Map<String, String> headder); // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Serializer.java // public class Serializer { // // private final ObjectMapper mapper; // // public Serializer() { // this(new ObjectMapperConfig().getConfiguredObjectMapper()); // } // // protected Serializer(ObjectMapper mapper) { // this.mapper = mapper; // } // // public <T> T deserialize(String input, Class<T> responseClass) { // if(Wrapped.class.isAssignableFrom(responseClass)) { // Object deserializedObject = deserializeWrapped(input); // // if(deserializedObject.getClass().isAssignableFrom(responseClass)) { // return responseClass.cast(deserializedObject); // } // else { // throw new SerializationException("input could not be serialized to " + responseClass.getCanonicalName()); // } // } // // return defaultDeserialisation(input, responseClass); // } // // private Object deserializeWrapped(String input) { // return defaultDeserialisation(input, Wrapper.class).getElement(); // } // // // public String serialize(Object obj) { // if(obj instanceof Wrapped) { // return serialize((Wrapped) obj); // } // // return defaultSerialization(obj); // } // // private String defaultSerialization(Object obj) { // try { // return mapper.writeValueAsString(obj); // } catch (JsonProcessingException e) { // throw new SerializationException("Could not serilize " + obj.getClass().getName() + " to string", e); // } // } // // private String serialize(Wrapped wrapped) { // return defaultSerialization(new Wrapper<>(wrapped)); // } // // private <T> T defaultDeserialisation(String input, Class<T> responseClass) { // try { // return mapper.readValue(input, responseClass); // } catch (IOException e) { // throw new SerializationException("Could not deseriliaze input to " + responseClass.getName(), e); // } // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapper.java // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonSerialize(using = WrapperSerializer.class) // @JsonDeserialize(using = WrapperDeserializer.class) // public class Wrapper<T> { // // private T element; // // // public Wrapper(T element) { // this.element = element; // } // // public T getElement() { // return element; // } // } // Path: src/main/java/de/fesere/hypermedia/cj/model/CjClient.java import de.fesere.hypermedia.cj.http.HTTPClient; import de.fesere.hypermedia.cj.serialization.Serializer; import de.fesere.hypermedia.cj.serialization.Wrapper; import java.net.URI; import java.util.HashMap; import java.util.Map; package de.fesere.hypermedia.cj.model; public class CjClient { private final HTTPClient httpClient;
private Serializer serializer = new Serializer();
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/CjClient.java
// Path: src/main/java/de/fesere/hypermedia/cj/http/HTTPClient.java // public interface HTTPClient { // // String getLink(URI uri); // // URI post(URI href, String body, Map<String, String> header); // // String put(URI href, String body, Map<String, String> headder); // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Serializer.java // public class Serializer { // // private final ObjectMapper mapper; // // public Serializer() { // this(new ObjectMapperConfig().getConfiguredObjectMapper()); // } // // protected Serializer(ObjectMapper mapper) { // this.mapper = mapper; // } // // public <T> T deserialize(String input, Class<T> responseClass) { // if(Wrapped.class.isAssignableFrom(responseClass)) { // Object deserializedObject = deserializeWrapped(input); // // if(deserializedObject.getClass().isAssignableFrom(responseClass)) { // return responseClass.cast(deserializedObject); // } // else { // throw new SerializationException("input could not be serialized to " + responseClass.getCanonicalName()); // } // } // // return defaultDeserialisation(input, responseClass); // } // // private Object deserializeWrapped(String input) { // return defaultDeserialisation(input, Wrapper.class).getElement(); // } // // // public String serialize(Object obj) { // if(obj instanceof Wrapped) { // return serialize((Wrapped) obj); // } // // return defaultSerialization(obj); // } // // private String defaultSerialization(Object obj) { // try { // return mapper.writeValueAsString(obj); // } catch (JsonProcessingException e) { // throw new SerializationException("Could not serilize " + obj.getClass().getName() + " to string", e); // } // } // // private String serialize(Wrapped wrapped) { // return defaultSerialization(new Wrapper<>(wrapped)); // } // // private <T> T defaultDeserialisation(String input, Class<T> responseClass) { // try { // return mapper.readValue(input, responseClass); // } catch (IOException e) { // throw new SerializationException("Could not deseriliaze input to " + responseClass.getName(), e); // } // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapper.java // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonSerialize(using = WrapperSerializer.class) // @JsonDeserialize(using = WrapperDeserializer.class) // public class Wrapper<T> { // // private T element; // // // public Wrapper(T element) { // this.element = element; // } // // public T getElement() { // return element; // } // }
import de.fesere.hypermedia.cj.http.HTTPClient; import de.fesere.hypermedia.cj.serialization.Serializer; import de.fesere.hypermedia.cj.serialization.Wrapper; import java.net.URI; import java.util.HashMap; import java.util.Map;
package de.fesere.hypermedia.cj.model; public class CjClient { private final HTTPClient httpClient; private Serializer serializer = new Serializer(); public CjClient(HTTPClient httpClient) { this.httpClient = httpClient; } public Collection follow(Query query) { URI queryURI = query.buildURI(); return readCollection(queryURI); } public Collection readCollection(URI uri) { String collectionJson = httpClient.getLink(uri); return deserializeCollection(collectionJson); } private Collection deserializeCollection(String collectionJson) {
// Path: src/main/java/de/fesere/hypermedia/cj/http/HTTPClient.java // public interface HTTPClient { // // String getLink(URI uri); // // URI post(URI href, String body, Map<String, String> header); // // String put(URI href, String body, Map<String, String> headder); // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Serializer.java // public class Serializer { // // private final ObjectMapper mapper; // // public Serializer() { // this(new ObjectMapperConfig().getConfiguredObjectMapper()); // } // // protected Serializer(ObjectMapper mapper) { // this.mapper = mapper; // } // // public <T> T deserialize(String input, Class<T> responseClass) { // if(Wrapped.class.isAssignableFrom(responseClass)) { // Object deserializedObject = deserializeWrapped(input); // // if(deserializedObject.getClass().isAssignableFrom(responseClass)) { // return responseClass.cast(deserializedObject); // } // else { // throw new SerializationException("input could not be serialized to " + responseClass.getCanonicalName()); // } // } // // return defaultDeserialisation(input, responseClass); // } // // private Object deserializeWrapped(String input) { // return defaultDeserialisation(input, Wrapper.class).getElement(); // } // // // public String serialize(Object obj) { // if(obj instanceof Wrapped) { // return serialize((Wrapped) obj); // } // // return defaultSerialization(obj); // } // // private String defaultSerialization(Object obj) { // try { // return mapper.writeValueAsString(obj); // } catch (JsonProcessingException e) { // throw new SerializationException("Could not serilize " + obj.getClass().getName() + " to string", e); // } // } // // private String serialize(Wrapped wrapped) { // return defaultSerialization(new Wrapper<>(wrapped)); // } // // private <T> T defaultDeserialisation(String input, Class<T> responseClass) { // try { // return mapper.readValue(input, responseClass); // } catch (IOException e) { // throw new SerializationException("Could not deseriliaze input to " + responseClass.getName(), e); // } // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapper.java // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonSerialize(using = WrapperSerializer.class) // @JsonDeserialize(using = WrapperDeserializer.class) // public class Wrapper<T> { // // private T element; // // // public Wrapper(T element) { // this.element = element; // } // // public T getElement() { // return element; // } // } // Path: src/main/java/de/fesere/hypermedia/cj/model/CjClient.java import de.fesere.hypermedia.cj.http.HTTPClient; import de.fesere.hypermedia.cj.serialization.Serializer; import de.fesere.hypermedia.cj.serialization.Wrapper; import java.net.URI; import java.util.HashMap; import java.util.Map; package de.fesere.hypermedia.cj.model; public class CjClient { private final HTTPClient httpClient; private Serializer serializer = new Serializer(); public CjClient(HTTPClient httpClient) { this.httpClient = httpClient; } public Collection follow(Query query) { URI queryURI = query.buildURI(); return readCollection(queryURI); } public Collection readCollection(URI uri) { String collectionJson = httpClient.getLink(uri); return deserializeCollection(collectionJson); } private Collection deserializeCollection(String collectionJson) {
return (Collection) serializer.deserialize(collectionJson, Wrapper.class).getElement();
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryBuilder.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // }
import de.fesere.hypermedia.cj.model.DataEntry;
package de.fesere.hypermedia.cj.model.builder; public class DataEntryBuilder { private String name; private String prompt = null; private boolean writeNullValue = false; private Object value; public DataEntryBuilder setName(String name) { this.name = name; return this; } public DataEntryBuilder setValue(Object value) { this.value = value; return this; } public DataEntryBuilder setNullValue() { writeNullValue = true; return this; } public DataEntryBuilder setPrompt(String prompt) { this.prompt = prompt; return this; }
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryBuilder.java import de.fesere.hypermedia.cj.model.DataEntry; package de.fesere.hypermedia.cj.model.builder; public class DataEntryBuilder { private String name; private String prompt = null; private boolean writeNullValue = false; private Object value; public DataEntryBuilder setName(String name) { this.name = name; return this; } public DataEntryBuilder setValue(Object value) { this.value = value; return this; } public DataEntryBuilder setNullValue() { writeNullValue = true; return this; } public DataEntryBuilder setPrompt(String prompt) { this.prompt = prompt; return this; }
public DataEntry build() {
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/example/employeeDB/transformations/DepratmentTransformer.java
// Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/Department.java // public class Department { // private final String nr; // private final String name; // private final URI link; // // public Department(String nr, String name, URI link) { // this.nr = nr; // this.name = name; // this.link = link; // } // // public URI getLink(){ // return link; // } // // // public String toString() { // return "Department [nr: " + nr + ", name:" + name+"]"; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonPropertyOrder({"href", "data", "links"}) // public class Item { // private final URI href; // private final List<DataEntry> data = new ArrayList<>(); // private List<Link> links = new ArrayList<>(); // // // public Item() { // this(Collections.<DataEntry>emptyList()); // } // // public Item(List<DataEntry> data) { // this((URI) null); // if (data != null) { // this.data.addAll(data); // } // } // // public Item(URI href) { // this(href, Collections.<Link>emptyList()); // } // // @JsonCreator // public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { // this.href = href; // this.links = links; // } // // public Item(URI href, List<DataEntry> entries, List<Link> links) { // this(href, links); // this.data.addAll(entries); // } // // public URI getHref() { // return this.href; // } // // public void addData(DataEntry dataEntry) { // data.add(dataEntry); // } // // public List<DataEntry> getData() { // return new ArrayList<>(data); // } // // public List<Link> getLinks() { // return links; // } // // public String getString(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof StringDataEntry) { // return ((StringDataEntry) found).getValue(); // } // throw new PropertyNotFoundException(name, href, String.class); // } // // public boolean isNullValue(String name) { // DataEntry found = findDataEntry(name); // // return found instanceof NullDataEntry; // } // // public int getInt(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Integer.parseInt(value.toString()); // // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public double getDouble(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Double.parseDouble(value.toString()); // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public boolean getBoolean(String name) { // DataEntry entry = findDataEntry(name); // if (entry instanceof BooleanDataEntry) { // return (boolean) entry.getValue(); // } // // throw new PropertyNotFoundException(name, href, Boolean.class); // } // // private DataEntry findDataEntry(String name) { // DataEntry found = null; // for (DataEntry entry : data) { // if (entry.getName().equals(name)) { // found = entry; // break; // } // } // if (found == null) { // throw new ElementNotFoundException("Did not find property '" + name + "' in '" + href + "'"); // } // return found; // } // // public Map<String, Object> extractDataMap() { // Map<String, Object> result = new HashMap<>(); // for (DataEntry entry : data) { // result.put(entry.getName(), entry.getValue()); // } // // return result; // } // // public Object getObject(String entryName) { // DataEntry entry = findDataEntry(entryName); // // return entry.getValue(); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // }
import de.fesere.hypermedia.cj.example.employeeDB.Department; import de.fesere.hypermedia.cj.model.Item; import de.fesere.hypermedia.cj.transformer.ReadTransformation;
package de.fesere.hypermedia.cj.example.employeeDB.transformations; public class DepratmentTransformer implements ReadTransformation<Department> { @Override
// Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/Department.java // public class Department { // private final String nr; // private final String name; // private final URI link; // // public Department(String nr, String name, URI link) { // this.nr = nr; // this.name = name; // this.link = link; // } // // public URI getLink(){ // return link; // } // // // public String toString() { // return "Department [nr: " + nr + ", name:" + name+"]"; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonPropertyOrder({"href", "data", "links"}) // public class Item { // private final URI href; // private final List<DataEntry> data = new ArrayList<>(); // private List<Link> links = new ArrayList<>(); // // // public Item() { // this(Collections.<DataEntry>emptyList()); // } // // public Item(List<DataEntry> data) { // this((URI) null); // if (data != null) { // this.data.addAll(data); // } // } // // public Item(URI href) { // this(href, Collections.<Link>emptyList()); // } // // @JsonCreator // public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { // this.href = href; // this.links = links; // } // // public Item(URI href, List<DataEntry> entries, List<Link> links) { // this(href, links); // this.data.addAll(entries); // } // // public URI getHref() { // return this.href; // } // // public void addData(DataEntry dataEntry) { // data.add(dataEntry); // } // // public List<DataEntry> getData() { // return new ArrayList<>(data); // } // // public List<Link> getLinks() { // return links; // } // // public String getString(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof StringDataEntry) { // return ((StringDataEntry) found).getValue(); // } // throw new PropertyNotFoundException(name, href, String.class); // } // // public boolean isNullValue(String name) { // DataEntry found = findDataEntry(name); // // return found instanceof NullDataEntry; // } // // public int getInt(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Integer.parseInt(value.toString()); // // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public double getDouble(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Double.parseDouble(value.toString()); // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public boolean getBoolean(String name) { // DataEntry entry = findDataEntry(name); // if (entry instanceof BooleanDataEntry) { // return (boolean) entry.getValue(); // } // // throw new PropertyNotFoundException(name, href, Boolean.class); // } // // private DataEntry findDataEntry(String name) { // DataEntry found = null; // for (DataEntry entry : data) { // if (entry.getName().equals(name)) { // found = entry; // break; // } // } // if (found == null) { // throw new ElementNotFoundException("Did not find property '" + name + "' in '" + href + "'"); // } // return found; // } // // public Map<String, Object> extractDataMap() { // Map<String, Object> result = new HashMap<>(); // for (DataEntry entry : data) { // result.put(entry.getName(), entry.getValue()); // } // // return result; // } // // public Object getObject(String entryName) { // DataEntry entry = findDataEntry(entryName); // // return entry.getValue(); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/transformations/DepratmentTransformer.java import de.fesere.hypermedia.cj.example.employeeDB.Department; import de.fesere.hypermedia.cj.model.Item; import de.fesere.hypermedia.cj.transformer.ReadTransformation; package de.fesere.hypermedia.cj.example.employeeDB.transformations; public class DepratmentTransformer implements ReadTransformation<Department> { @Override
public Department transform(Item item) {
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/builder/LinkBuilder.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/Link.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // public class Link { // // private final URI href; // private final String prompt; // private String rel; // // @JsonCreator // public Link(@JsonProperty("rel") String rel, @JsonProperty("href") URI href, @JsonProperty("prompt") String prompt){ // this.rel = rel; // this.href = href; // this.prompt = prompt; // } // // public String getRel() { // return this.rel; // } // // public URI getHref() { // return href; // } // // public String getPrompt() { // return prompt; // } // }
import de.fesere.hypermedia.cj.model.Link; import java.net.URI; import java.util.LinkedList; import java.util.List;
package de.fesere.hypermedia.cj.model.builder; public class LinkBuilder { private UriConstructor uriConstructor;
// Path: src/main/java/de/fesere/hypermedia/cj/model/Link.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // public class Link { // // private final URI href; // private final String prompt; // private String rel; // // @JsonCreator // public Link(@JsonProperty("rel") String rel, @JsonProperty("href") URI href, @JsonProperty("prompt") String prompt){ // this.rel = rel; // this.href = href; // this.prompt = prompt; // } // // public String getRel() { // return this.rel; // } // // public URI getHref() { // return href; // } // // public String getPrompt() { // return prompt; // } // } // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/LinkBuilder.java import de.fesere.hypermedia.cj.model.Link; import java.net.URI; import java.util.LinkedList; import java.util.List; package de.fesere.hypermedia.cj.model.builder; public class LinkBuilder { private UriConstructor uriConstructor;
private List<Link> links = new LinkedList<>();
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/transformer/TwoWayTransformerTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonPropertyOrder({"href", "data", "links"}) // public class Item { // private final URI href; // private final List<DataEntry> data = new ArrayList<>(); // private List<Link> links = new ArrayList<>(); // // // public Item() { // this(Collections.<DataEntry>emptyList()); // } // // public Item(List<DataEntry> data) { // this((URI) null); // if (data != null) { // this.data.addAll(data); // } // } // // public Item(URI href) { // this(href, Collections.<Link>emptyList()); // } // // @JsonCreator // public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { // this.href = href; // this.links = links; // } // // public Item(URI href, List<DataEntry> entries, List<Link> links) { // this(href, links); // this.data.addAll(entries); // } // // public URI getHref() { // return this.href; // } // // public void addData(DataEntry dataEntry) { // data.add(dataEntry); // } // // public List<DataEntry> getData() { // return new ArrayList<>(data); // } // // public List<Link> getLinks() { // return links; // } // // public String getString(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof StringDataEntry) { // return ((StringDataEntry) found).getValue(); // } // throw new PropertyNotFoundException(name, href, String.class); // } // // public boolean isNullValue(String name) { // DataEntry found = findDataEntry(name); // // return found instanceof NullDataEntry; // } // // public int getInt(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Integer.parseInt(value.toString()); // // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public double getDouble(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Double.parseDouble(value.toString()); // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public boolean getBoolean(String name) { // DataEntry entry = findDataEntry(name); // if (entry instanceof BooleanDataEntry) { // return (boolean) entry.getValue(); // } // // throw new PropertyNotFoundException(name, href, Boolean.class); // } // // private DataEntry findDataEntry(String name) { // DataEntry found = null; // for (DataEntry entry : data) { // if (entry.getName().equals(name)) { // found = entry; // break; // } // } // if (found == null) { // throw new ElementNotFoundException("Did not find property '" + name + "' in '" + href + "'"); // } // return found; // } // // public Map<String, Object> extractDataMap() { // Map<String, Object> result = new HashMap<>(); // for (DataEntry entry : data) { // result.put(entry.getName(), entry.getValue()); // } // // return result; // } // // public Object getObject(String entryName) { // DataEntry entry = findDataEntry(entryName); // // return entry.getValue(); // } // }
import de.fesere.hypermedia.cj.model.Item; import org.junit.Test;
package de.fesere.hypermedia.cj.transformer; //For sake of consistency public class TwoWayTransformerTest { private DummyTransformer t = new DummyTransformer(); @Test(expected = IllegalStateException.class) public void testConvertToItem() throws Exception { t.transform("foo"); } @Test(expected = IllegalStateException.class) public void testConvertFromItem() throws Exception {
// Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java // @JsonSerialize // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JsonPropertyOrder({"href", "data", "links"}) // public class Item { // private final URI href; // private final List<DataEntry> data = new ArrayList<>(); // private List<Link> links = new ArrayList<>(); // // // public Item() { // this(Collections.<DataEntry>emptyList()); // } // // public Item(List<DataEntry> data) { // this((URI) null); // if (data != null) { // this.data.addAll(data); // } // } // // public Item(URI href) { // this(href, Collections.<Link>emptyList()); // } // // @JsonCreator // public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { // this.href = href; // this.links = links; // } // // public Item(URI href, List<DataEntry> entries, List<Link> links) { // this(href, links); // this.data.addAll(entries); // } // // public URI getHref() { // return this.href; // } // // public void addData(DataEntry dataEntry) { // data.add(dataEntry); // } // // public List<DataEntry> getData() { // return new ArrayList<>(data); // } // // public List<Link> getLinks() { // return links; // } // // public String getString(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof StringDataEntry) { // return ((StringDataEntry) found).getValue(); // } // throw new PropertyNotFoundException(name, href, String.class); // } // // public boolean isNullValue(String name) { // DataEntry found = findDataEntry(name); // // return found instanceof NullDataEntry; // } // // public int getInt(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Integer.parseInt(value.toString()); // // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public double getDouble(String name) { // DataEntry found = findDataEntry(name); // // if (found instanceof NumberDataEntry) { // Number value = ((NumberDataEntry) found).getValue(); // return Double.parseDouble(value.toString()); // } // // throw new PropertyNotFoundException(name, href, Number.class); // } // // public boolean getBoolean(String name) { // DataEntry entry = findDataEntry(name); // if (entry instanceof BooleanDataEntry) { // return (boolean) entry.getValue(); // } // // throw new PropertyNotFoundException(name, href, Boolean.class); // } // // private DataEntry findDataEntry(String name) { // DataEntry found = null; // for (DataEntry entry : data) { // if (entry.getName().equals(name)) { // found = entry; // break; // } // } // if (found == null) { // throw new ElementNotFoundException("Did not find property '" + name + "' in '" + href + "'"); // } // return found; // } // // public Map<String, Object> extractDataMap() { // Map<String, Object> result = new HashMap<>(); // for (DataEntry entry : data) { // result.put(entry.getName(), entry.getValue()); // } // // return result; // } // // public Object getObject(String entryName) { // DataEntry entry = findDataEntry(entryName); // // return entry.getValue(); // } // } // Path: src/test/java/de/fesere/hypermedia/cj/transformer/TwoWayTransformerTest.java import de.fesere.hypermedia.cj.model.Item; import org.junit.Test; package de.fesere.hypermedia.cj.transformer; //For sake of consistency public class TwoWayTransformerTest { private DummyTransformer t = new DummyTransformer(); @Test(expected = IllegalStateException.class) public void testConvertToItem() throws Exception { t.transform("foo"); } @Test(expected = IllegalStateException.class) public void testConvertFromItem() throws Exception {
t.transform(new Item());
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Collection.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/CollectionHasErrorsException.java // public class CollectionHasErrorsException extends RuntimeException { // // public CollectionHasErrorsException(Error error) { // super(error.getTitle() + " (Code " + error.getCode() + ") : " + error.getMessage() + "."); // } // // // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // }
import com.fasterxml.jackson.annotation.*; import de.fesere.hypermedia.cj.exceptions.CollectionHasErrorsException; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.net.URI; import java.util.ArrayList; import java.util.List; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
package de.fesere.hypermedia.cj.model; @JsonTypeName("collection") @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE) @JsonPropertyOrder({"version", "href", "links", "error", "items", "queries", "template"})
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/CollectionHasErrorsException.java // public class CollectionHasErrorsException extends RuntimeException { // // public CollectionHasErrorsException(Error error) { // super(error.getTitle() + " (Code " + error.getCode() + ") : " + error.getMessage() + "."); // } // // // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Collection.java import com.fasterxml.jackson.annotation.*; import de.fesere.hypermedia.cj.exceptions.CollectionHasErrorsException; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.net.URI; import java.util.ArrayList; import java.util.List; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; package de.fesere.hypermedia.cj.model; @JsonTypeName("collection") @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE) @JsonPropertyOrder({"version", "href", "links", "error", "items", "queries", "template"})
public class Collection implements Wrapped{
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Collection.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/CollectionHasErrorsException.java // public class CollectionHasErrorsException extends RuntimeException { // // public CollectionHasErrorsException(Error error) { // super(error.getTitle() + " (Code " + error.getCode() + ") : " + error.getMessage() + "."); // } // // // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // }
import com.fasterxml.jackson.annotation.*; import de.fesere.hypermedia.cj.exceptions.CollectionHasErrorsException; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.net.URI; import java.util.ArrayList; import java.util.List; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
if(items != null) { this.items.addAll(items); } if(queries != null) { this.queries.addAll(queries); } if(links != null) { this.links.addAll(links); } this.template = template; } public URI getHref() { return this.href; } public List<Item> getItems() { throwExceptionOnError(); return new ArrayList<>(items); } public List<Link> getLinks() { throwExceptionOnError(); return new ArrayList<>(links); } private void throwExceptionOnError() { if(hasError()) {
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/CollectionHasErrorsException.java // public class CollectionHasErrorsException extends RuntimeException { // // public CollectionHasErrorsException(Error error) { // super(error.getTitle() + " (Code " + error.getCode() + ") : " + error.getMessage() + "."); // } // // // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Collection.java import com.fasterxml.jackson.annotation.*; import de.fesere.hypermedia.cj.exceptions.CollectionHasErrorsException; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.net.URI; import java.util.ArrayList; import java.util.List; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; if(items != null) { this.items.addAll(items); } if(queries != null) { this.queries.addAll(queries); } if(links != null) { this.links.addAll(links); } this.template = template; } public URI getHref() { return this.href; } public List<Item> getItems() { throwExceptionOnError(); return new ArrayList<>(items); } public List<Link> getLinks() { throwExceptionOnError(); return new ArrayList<>(links); } private void throwExceptionOnError() { if(hasError()) {
throw new CollectionHasErrorsException(getError());
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Collection.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/CollectionHasErrorsException.java // public class CollectionHasErrorsException extends RuntimeException { // // public CollectionHasErrorsException(Error error) { // super(error.getTitle() + " (Code " + error.getCode() + ") : " + error.getMessage() + "."); // } // // // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // }
import com.fasterxml.jackson.annotation.*; import de.fesere.hypermedia.cj.exceptions.CollectionHasErrorsException; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.net.URI; import java.util.ArrayList; import java.util.List; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
public URI getHref() { return this.href; } public List<Item> getItems() { throwExceptionOnError(); return new ArrayList<>(items); } public List<Link> getLinks() { throwExceptionOnError(); return new ArrayList<>(links); } private void throwExceptionOnError() { if(hasError()) { throw new CollectionHasErrorsException(getError()); } } public List<Query> getQueries() { throwExceptionOnError(); return new ArrayList<>(queries); }
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/CollectionHasErrorsException.java // public class CollectionHasErrorsException extends RuntimeException { // // public CollectionHasErrorsException(Error error) { // super(error.getTitle() + " (Code " + error.getCode() + ") : " + error.getMessage() + "."); // } // // // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Collection.java import com.fasterxml.jackson.annotation.*; import de.fesere.hypermedia.cj.exceptions.CollectionHasErrorsException; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.net.URI; import java.util.ArrayList; import java.util.List; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; public URI getHref() { return this.href; } public List<Item> getItems() { throwExceptionOnError(); return new ArrayList<>(items); } public List<Link> getLinks() { throwExceptionOnError(); return new ArrayList<>(links); } private void throwExceptionOnError() { if(hasError()) { throw new CollectionHasErrorsException(getError()); } } public List<Query> getQueries() { throwExceptionOnError(); return new ArrayList<>(queries); }
public <T> List<T> transform(ReadTransformation<T> transformer) {
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Collection.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/CollectionHasErrorsException.java // public class CollectionHasErrorsException extends RuntimeException { // // public CollectionHasErrorsException(Error error) { // super(error.getTitle() + " (Code " + error.getCode() + ") : " + error.getMessage() + "."); // } // // // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // }
import com.fasterxml.jackson.annotation.*; import de.fesere.hypermedia.cj.exceptions.CollectionHasErrorsException; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.net.URI; import java.util.ArrayList; import java.util.List; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
result.add(convertedItem); } } return result; } public boolean hasError() { return error != null; } public Error getError() { return error; } public Link getLink(String rel) { throwExceptionOnError(); return findByRel(links,rel); } private <T extends Link> T findByRel(List<T> elements, String rel) { for(T linkable : elements ) { if(linkable.getRel().equalsIgnoreCase(rel)) { return linkable; } }
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/CollectionHasErrorsException.java // public class CollectionHasErrorsException extends RuntimeException { // // public CollectionHasErrorsException(Error error) { // super(error.getTitle() + " (Code " + error.getCode() + ") : " + error.getMessage() + "."); // } // // // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/serialization/Wrapped.java // public interface Wrapped { // } // // Path: src/main/java/de/fesere/hypermedia/cj/transformer/ReadTransformation.java // public interface ReadTransformation<T> { // // T transform(Item item); // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Collection.java import com.fasterxml.jackson.annotation.*; import de.fesere.hypermedia.cj.exceptions.CollectionHasErrorsException; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.serialization.Wrapped; import de.fesere.hypermedia.cj.transformer.ReadTransformation; import java.net.URI; import java.util.ArrayList; import java.util.List; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; result.add(convertedItem); } } return result; } public boolean hasError() { return error != null; } public Error getError() { return error; } public Link getLink(String rel) { throwExceptionOnError(); return findByRel(links,rel); } private <T extends Link> T findByRel(List<T> elements, String rel) { for(T linkable : elements ) { if(linkable.getRel().equalsIgnoreCase(rel)) { return linkable; } }
throw new ElementNotFoundException("Did not find element '"+rel+"' in collection " + href );
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/ExampleFilesTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/CollectionHasErrorsException.java // public class CollectionHasErrorsException extends RuntimeException { // // public CollectionHasErrorsException(Error error) { // super(error.getTitle() + " (Code " + error.getCode() + ") : " + error.getMessage() + "."); // } // // // }
import de.fesere.hypermedia.cj.exceptions.CollectionHasErrorsException; import org.junit.Test; import java.net.URI; import static junit.framework.Assert.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.core.Is.is;
assertEquals(URI.create("http://example.org/friends/"), result.getHref()); assertEquals("1.0", result.getVersion()); assertFalse(result.hasError()); assertThat("Incorrect number of links ", result.getLinks(), hasSize(3)); assertThat("Incorrect number of items ", result.getItems(), hasSize(3)); assertThat("Incorrect number of queries ", result.getQueries(),hasSize(1)); assertThat("Template not found ", result.getTemplate(), is(notNullValue())); assertThat(result.getLinks(), hasSize(3)); assertThat(result.getLink("feed").getRel(), is("feed")); assertThat(result.getLink("feed").getHref(), is(URI.create("http://example.org/friends/rss"))); assertThat(result.getQueries(), hasSize(1)); assertThat(result.getQuery("search").getData(),hasSize(1) ); } @Test public void testCollectionWithError() { Collection result = readCollection("examples/collection-with-error.json"); assertTrue("no error was set", result.hasError()); assertEquals("Server Error", result.getError().getTitle()); assertEquals("X1C2", result.getError().getCode()); assertFalse(result.getError().getMessage().isEmpty()); }
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/CollectionHasErrorsException.java // public class CollectionHasErrorsException extends RuntimeException { // // public CollectionHasErrorsException(Error error) { // super(error.getTitle() + " (Code " + error.getCode() + ") : " + error.getMessage() + "."); // } // // // } // Path: src/test/java/de/fesere/hypermedia/cj/model/ExampleFilesTest.java import de.fesere.hypermedia.cj.exceptions.CollectionHasErrorsException; import org.junit.Test; import java.net.URI; import static junit.framework.Assert.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.core.Is.is; assertEquals(URI.create("http://example.org/friends/"), result.getHref()); assertEquals("1.0", result.getVersion()); assertFalse(result.hasError()); assertThat("Incorrect number of links ", result.getLinks(), hasSize(3)); assertThat("Incorrect number of items ", result.getItems(), hasSize(3)); assertThat("Incorrect number of queries ", result.getQueries(),hasSize(1)); assertThat("Template not found ", result.getTemplate(), is(notNullValue())); assertThat(result.getLinks(), hasSize(3)); assertThat(result.getLink("feed").getRel(), is("feed")); assertThat(result.getLink("feed").getHref(), is(URI.create("http://example.org/friends/rss"))); assertThat(result.getQueries(), hasSize(1)); assertThat(result.getQuery("search").getData(),hasSize(1) ); } @Test public void testCollectionWithError() { Collection result = readCollection("examples/collection-with-error.json"); assertTrue("no error was set", result.hasError()); assertEquals("Server Error", result.getError().getTitle()); assertEquals("X1C2", result.getError().getCode()); assertFalse(result.getError().getMessage().isEmpty()); }
@Test(expected = CollectionHasErrorsException.class)
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/ItemSerializationTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/MalformedDataValueException.java // public class MalformedDataValueException extends RuntimeException { // // public MalformedDataValueException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // }
import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.MalformedDataValueException; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import org.junit.Assert; import org.junit.Test; import java.net.URI; import static junit.framework.Assert.assertEquals; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.core.Is.is;
package de.fesere.hypermedia.cj.model; public class ItemSerializationTest extends SerializationTestBase { private static final URI TEST_COM_ITEM = URI.create("http://writeToStringExample.com/item/1"); @Test public void testPOJOtoJSON() { Item classUnderTest = new Item(TEST_COM_ITEM); assertSerialization("{\"href\":\"http://writeToStringExample.com/item/1\"}", classUnderTest); } @Test public void testJSONtoPOJO() { String givenJSON = "{\"href\":\"http://writeToStringExample.com/item/1\"}"; Item item = serializer.deserialize(givenJSON, Item.class); assertEquals(TEST_COM_ITEM, item.getHref()); } @Test public void testJSONwithAllPropertiesToPOJO() { String givenJSON = "{\"href\":\"http://writeToStringExample.com/item/1\", \"data\":[{\"name\":\"foo\", \"value\":\"bar\", \"prompt\":\"foos prompt\"}]}"; Item item = serializer.deserialize(givenJSON, Item.class); assertThat(item.getHref(), is(TEST_COM_ITEM)); DataEntry dataEntry = item.getData().get(0); assertThat(dataEntry.getPrompt(), is("foos prompt")); assertThat(dataEntry.getName(), is("foo")); assertThat((String) dataEntry.getValue(), is("bar")); } @Test public void testSerializeItemWithSingleDataEntry() { Item item = new Item(TEST_COM_ITEM);
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/MalformedDataValueException.java // public class MalformedDataValueException extends RuntimeException { // // public MalformedDataValueException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // } // Path: src/test/java/de/fesere/hypermedia/cj/model/ItemSerializationTest.java import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.MalformedDataValueException; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import org.junit.Assert; import org.junit.Test; import java.net.URI; import static junit.framework.Assert.assertEquals; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.core.Is.is; package de.fesere.hypermedia.cj.model; public class ItemSerializationTest extends SerializationTestBase { private static final URI TEST_COM_ITEM = URI.create("http://writeToStringExample.com/item/1"); @Test public void testPOJOtoJSON() { Item classUnderTest = new Item(TEST_COM_ITEM); assertSerialization("{\"href\":\"http://writeToStringExample.com/item/1\"}", classUnderTest); } @Test public void testJSONtoPOJO() { String givenJSON = "{\"href\":\"http://writeToStringExample.com/item/1\"}"; Item item = serializer.deserialize(givenJSON, Item.class); assertEquals(TEST_COM_ITEM, item.getHref()); } @Test public void testJSONwithAllPropertiesToPOJO() { String givenJSON = "{\"href\":\"http://writeToStringExample.com/item/1\", \"data\":[{\"name\":\"foo\", \"value\":\"bar\", \"prompt\":\"foos prompt\"}]}"; Item item = serializer.deserialize(givenJSON, Item.class); assertThat(item.getHref(), is(TEST_COM_ITEM)); DataEntry dataEntry = item.getData().get(0); assertThat(dataEntry.getPrompt(), is("foos prompt")); assertThat(dataEntry.getName(), is("foo")); assertThat((String) dataEntry.getValue(), is("bar")); } @Test public void testSerializeItemWithSingleDataEntry() { Item item = new Item(TEST_COM_ITEM);
item.addData(new StringDataEntry("foo", "bar"));
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/ItemSerializationTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/MalformedDataValueException.java // public class MalformedDataValueException extends RuntimeException { // // public MalformedDataValueException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // }
import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.MalformedDataValueException; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import org.junit.Assert; import org.junit.Test; import java.net.URI; import static junit.framework.Assert.assertEquals; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.core.Is.is;
String givenJSON = "{\"href\":\"http://writeToStringExample.com/item/1\", \"data\":[{\"name\":\"foo\", \"value\":\"bar\", \"prompt\":\"foos prompt\"}]}"; Item item = serializer.deserialize(givenJSON, Item.class); assertThat(item.getHref(), is(TEST_COM_ITEM)); DataEntry dataEntry = item.getData().get(0); assertThat(dataEntry.getPrompt(), is("foos prompt")); assertThat(dataEntry.getName(), is("foo")); assertThat((String) dataEntry.getValue(), is("bar")); } @Test public void testSerializeItemWithSingleDataEntry() { Item item = new Item(TEST_COM_ITEM); item.addData(new StringDataEntry("foo", "bar")); assertSerialization("{\"href\":\"http://writeToStringExample.com/item/1\", \"data\":[{\"name\":\"foo\", \"value\":\"bar\"}]}", item); } @Test public void testDeserializeItemWithSingleDataEntry() { String givenJSON = "{\"href\":\"http://writeToStringExample.com/item/1\", \"data\":[{\"name\":\"foo\", \"value\":\"bar\"}]}"; Item item = serializer.deserialize(givenJSON, Item.class); assertEquals(TEST_COM_ITEM, item.getHref()); assertThat(item.getData(), contains(name("foo"))); }
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/MalformedDataValueException.java // public class MalformedDataValueException extends RuntimeException { // // public MalformedDataValueException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // } // Path: src/test/java/de/fesere/hypermedia/cj/model/ItemSerializationTest.java import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.MalformedDataValueException; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import org.junit.Assert; import org.junit.Test; import java.net.URI; import static junit.framework.Assert.assertEquals; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.core.Is.is; String givenJSON = "{\"href\":\"http://writeToStringExample.com/item/1\", \"data\":[{\"name\":\"foo\", \"value\":\"bar\", \"prompt\":\"foos prompt\"}]}"; Item item = serializer.deserialize(givenJSON, Item.class); assertThat(item.getHref(), is(TEST_COM_ITEM)); DataEntry dataEntry = item.getData().get(0); assertThat(dataEntry.getPrompt(), is("foos prompt")); assertThat(dataEntry.getName(), is("foo")); assertThat((String) dataEntry.getValue(), is("bar")); } @Test public void testSerializeItemWithSingleDataEntry() { Item item = new Item(TEST_COM_ITEM); item.addData(new StringDataEntry("foo", "bar")); assertSerialization("{\"href\":\"http://writeToStringExample.com/item/1\", \"data\":[{\"name\":\"foo\", \"value\":\"bar\"}]}", item); } @Test public void testDeserializeItemWithSingleDataEntry() { String givenJSON = "{\"href\":\"http://writeToStringExample.com/item/1\", \"data\":[{\"name\":\"foo\", \"value\":\"bar\"}]}"; Item item = serializer.deserialize(givenJSON, Item.class); assertEquals(TEST_COM_ITEM, item.getHref()); assertThat(item.getData(), contains(name("foo"))); }
@Test(expected = ElementNotFoundException.class)
felipesere/collection-json-parser
src/test/java/de/fesere/hypermedia/cj/model/ItemSerializationTest.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/MalformedDataValueException.java // public class MalformedDataValueException extends RuntimeException { // // public MalformedDataValueException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // }
import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.MalformedDataValueException; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import org.junit.Assert; import org.junit.Test; import java.net.URI; import static junit.framework.Assert.assertEquals; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.core.Is.is;
} @Test(expected = ElementNotFoundException.class) public void testDeserializeItemWithSingleDataEntryMissingString() { String givenJSON = "{\"href\":\"http://writeToStringExample.com/item/1\", \"data\":[{\"name\":\"age\", \"value\":\"24\"}]}"; Item item = serializer.deserialize(givenJSON, Item.class); item.getString("doesNotExist"); } @Test(expected = ElementNotFoundException.class) public void testDeserializeItemWithSingleDataEntryMissingInteger() { String givenJSON = "{\"href\":\"http://writeToStringExample.com/item/1\", \"data\":[{\"name\":\"age\", \"value\":\"24\"}]}"; Item item = serializer.deserialize(givenJSON, Item.class); item.getInt("doesNotExist"); } @Test public void testDeserializeItemWithSingleDataEntryContainingInt() { String givenJSON = "{\"href\":\"http://writeToStringExample.com/item/1\", \"data\":[{\"name\":\"age\", \"value\":24}]}"; Item item = serializer.deserialize(givenJSON, Item.class); assertEquals(TEST_COM_ITEM, item.getHref()); assertThat(item.getData(), contains(name("age"))); assertThat(item.getInt("age"), is(24)); }
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/MalformedDataValueException.java // public class MalformedDataValueException extends RuntimeException { // // public MalformedDataValueException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // } // Path: src/test/java/de/fesere/hypermedia/cj/model/ItemSerializationTest.java import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.MalformedDataValueException; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import org.junit.Assert; import org.junit.Test; import java.net.URI; import static junit.framework.Assert.assertEquals; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.core.Is.is; } @Test(expected = ElementNotFoundException.class) public void testDeserializeItemWithSingleDataEntryMissingString() { String givenJSON = "{\"href\":\"http://writeToStringExample.com/item/1\", \"data\":[{\"name\":\"age\", \"value\":\"24\"}]}"; Item item = serializer.deserialize(givenJSON, Item.class); item.getString("doesNotExist"); } @Test(expected = ElementNotFoundException.class) public void testDeserializeItemWithSingleDataEntryMissingInteger() { String givenJSON = "{\"href\":\"http://writeToStringExample.com/item/1\", \"data\":[{\"name\":\"age\", \"value\":\"24\"}]}"; Item item = serializer.deserialize(givenJSON, Item.class); item.getInt("doesNotExist"); } @Test public void testDeserializeItemWithSingleDataEntryContainingInt() { String givenJSON = "{\"href\":\"http://writeToStringExample.com/item/1\", \"data\":[{\"name\":\"age\", \"value\":24}]}"; Item item = serializer.deserialize(givenJSON, Item.class); assertEquals(TEST_COM_ITEM, item.getHref()); assertThat(item.getData(), contains(name("age"))); assertThat(item.getInt("age"), is(24)); }
@Test(expected = MalformedDataValueException.class)
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Item.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/PropertyNotFoundException.java // public class PropertyNotFoundException extends MalformedDataValueException { // public PropertyNotFoundException(String name, URI href, Class type) { // super("Did not find property '" + name + "' as " + type.getSimpleName() +" in " + href); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/BooleanDataEntry.java // public class BooleanDataEntry extends BaseDataEntry<Boolean> { // private final boolean value; // // public BooleanDataEntry(String name, boolean booleanValue, String prompt) { // super(name, prompt); // this.value = booleanValue; // } // // @Override // public Boolean getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NullDataEntry.java // public class NullDataEntry extends BaseDataEntry { // public NullDataEntry(String name, String prompt) { // super(name, prompt); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // }
import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.PropertyNotFoundException; import de.fesere.hypermedia.cj.model.data.BooleanDataEntry; import de.fesere.hypermedia.cj.model.data.NullDataEntry; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import java.net.URI; import java.util.*;
@JsonCreator public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { this.href = href; this.links = links; } public Item(URI href, List<DataEntry> entries, List<Link> links) { this(href, links); this.data.addAll(entries); } public URI getHref() { return this.href; } public void addData(DataEntry dataEntry) { data.add(dataEntry); } public List<DataEntry> getData() { return new ArrayList<>(data); } public List<Link> getLinks() { return links; } public String getString(String name) { DataEntry found = findDataEntry(name);
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/PropertyNotFoundException.java // public class PropertyNotFoundException extends MalformedDataValueException { // public PropertyNotFoundException(String name, URI href, Class type) { // super("Did not find property '" + name + "' as " + type.getSimpleName() +" in " + href); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/BooleanDataEntry.java // public class BooleanDataEntry extends BaseDataEntry<Boolean> { // private final boolean value; // // public BooleanDataEntry(String name, boolean booleanValue, String prompt) { // super(name, prompt); // this.value = booleanValue; // } // // @Override // public Boolean getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NullDataEntry.java // public class NullDataEntry extends BaseDataEntry { // public NullDataEntry(String name, String prompt) { // super(name, prompt); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.PropertyNotFoundException; import de.fesere.hypermedia.cj.model.data.BooleanDataEntry; import de.fesere.hypermedia.cj.model.data.NullDataEntry; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import java.net.URI; import java.util.*; @JsonCreator public Item(@JsonProperty("href") URI href, @JsonProperty("links") List<Link> links) { this.href = href; this.links = links; } public Item(URI href, List<DataEntry> entries, List<Link> links) { this(href, links); this.data.addAll(entries); } public URI getHref() { return this.href; } public void addData(DataEntry dataEntry) { data.add(dataEntry); } public List<DataEntry> getData() { return new ArrayList<>(data); } public List<Link> getLinks() { return links; } public String getString(String name) { DataEntry found = findDataEntry(name);
if (found instanceof StringDataEntry) {
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Item.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/PropertyNotFoundException.java // public class PropertyNotFoundException extends MalformedDataValueException { // public PropertyNotFoundException(String name, URI href, Class type) { // super("Did not find property '" + name + "' as " + type.getSimpleName() +" in " + href); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/BooleanDataEntry.java // public class BooleanDataEntry extends BaseDataEntry<Boolean> { // private final boolean value; // // public BooleanDataEntry(String name, boolean booleanValue, String prompt) { // super(name, prompt); // this.value = booleanValue; // } // // @Override // public Boolean getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NullDataEntry.java // public class NullDataEntry extends BaseDataEntry { // public NullDataEntry(String name, String prompt) { // super(name, prompt); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // }
import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.PropertyNotFoundException; import de.fesere.hypermedia.cj.model.data.BooleanDataEntry; import de.fesere.hypermedia.cj.model.data.NullDataEntry; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import java.net.URI; import java.util.*;
this.links = links; } public Item(URI href, List<DataEntry> entries, List<Link> links) { this(href, links); this.data.addAll(entries); } public URI getHref() { return this.href; } public void addData(DataEntry dataEntry) { data.add(dataEntry); } public List<DataEntry> getData() { return new ArrayList<>(data); } public List<Link> getLinks() { return links; } public String getString(String name) { DataEntry found = findDataEntry(name); if (found instanceof StringDataEntry) { return ((StringDataEntry) found).getValue(); }
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/PropertyNotFoundException.java // public class PropertyNotFoundException extends MalformedDataValueException { // public PropertyNotFoundException(String name, URI href, Class type) { // super("Did not find property '" + name + "' as " + type.getSimpleName() +" in " + href); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/BooleanDataEntry.java // public class BooleanDataEntry extends BaseDataEntry<Boolean> { // private final boolean value; // // public BooleanDataEntry(String name, boolean booleanValue, String prompt) { // super(name, prompt); // this.value = booleanValue; // } // // @Override // public Boolean getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NullDataEntry.java // public class NullDataEntry extends BaseDataEntry { // public NullDataEntry(String name, String prompt) { // super(name, prompt); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.PropertyNotFoundException; import de.fesere.hypermedia.cj.model.data.BooleanDataEntry; import de.fesere.hypermedia.cj.model.data.NullDataEntry; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import java.net.URI; import java.util.*; this.links = links; } public Item(URI href, List<DataEntry> entries, List<Link> links) { this(href, links); this.data.addAll(entries); } public URI getHref() { return this.href; } public void addData(DataEntry dataEntry) { data.add(dataEntry); } public List<DataEntry> getData() { return new ArrayList<>(data); } public List<Link> getLinks() { return links; } public String getString(String name) { DataEntry found = findDataEntry(name); if (found instanceof StringDataEntry) { return ((StringDataEntry) found).getValue(); }
throw new PropertyNotFoundException(name, href, String.class);
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Item.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/PropertyNotFoundException.java // public class PropertyNotFoundException extends MalformedDataValueException { // public PropertyNotFoundException(String name, URI href, Class type) { // super("Did not find property '" + name + "' as " + type.getSimpleName() +" in " + href); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/BooleanDataEntry.java // public class BooleanDataEntry extends BaseDataEntry<Boolean> { // private final boolean value; // // public BooleanDataEntry(String name, boolean booleanValue, String prompt) { // super(name, prompt); // this.value = booleanValue; // } // // @Override // public Boolean getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NullDataEntry.java // public class NullDataEntry extends BaseDataEntry { // public NullDataEntry(String name, String prompt) { // super(name, prompt); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // }
import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.PropertyNotFoundException; import de.fesere.hypermedia.cj.model.data.BooleanDataEntry; import de.fesere.hypermedia.cj.model.data.NullDataEntry; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import java.net.URI; import java.util.*;
} public URI getHref() { return this.href; } public void addData(DataEntry dataEntry) { data.add(dataEntry); } public List<DataEntry> getData() { return new ArrayList<>(data); } public List<Link> getLinks() { return links; } public String getString(String name) { DataEntry found = findDataEntry(name); if (found instanceof StringDataEntry) { return ((StringDataEntry) found).getValue(); } throw new PropertyNotFoundException(name, href, String.class); } public boolean isNullValue(String name) { DataEntry found = findDataEntry(name);
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/PropertyNotFoundException.java // public class PropertyNotFoundException extends MalformedDataValueException { // public PropertyNotFoundException(String name, URI href, Class type) { // super("Did not find property '" + name + "' as " + type.getSimpleName() +" in " + href); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/BooleanDataEntry.java // public class BooleanDataEntry extends BaseDataEntry<Boolean> { // private final boolean value; // // public BooleanDataEntry(String name, boolean booleanValue, String prompt) { // super(name, prompt); // this.value = booleanValue; // } // // @Override // public Boolean getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NullDataEntry.java // public class NullDataEntry extends BaseDataEntry { // public NullDataEntry(String name, String prompt) { // super(name, prompt); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.PropertyNotFoundException; import de.fesere.hypermedia.cj.model.data.BooleanDataEntry; import de.fesere.hypermedia.cj.model.data.NullDataEntry; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import java.net.URI; import java.util.*; } public URI getHref() { return this.href; } public void addData(DataEntry dataEntry) { data.add(dataEntry); } public List<DataEntry> getData() { return new ArrayList<>(data); } public List<Link> getLinks() { return links; } public String getString(String name) { DataEntry found = findDataEntry(name); if (found instanceof StringDataEntry) { return ((StringDataEntry) found).getValue(); } throw new PropertyNotFoundException(name, href, String.class); } public boolean isNullValue(String name) { DataEntry found = findDataEntry(name);
return found instanceof NullDataEntry;
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Item.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/PropertyNotFoundException.java // public class PropertyNotFoundException extends MalformedDataValueException { // public PropertyNotFoundException(String name, URI href, Class type) { // super("Did not find property '" + name + "' as " + type.getSimpleName() +" in " + href); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/BooleanDataEntry.java // public class BooleanDataEntry extends BaseDataEntry<Boolean> { // private final boolean value; // // public BooleanDataEntry(String name, boolean booleanValue, String prompt) { // super(name, prompt); // this.value = booleanValue; // } // // @Override // public Boolean getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NullDataEntry.java // public class NullDataEntry extends BaseDataEntry { // public NullDataEntry(String name, String prompt) { // super(name, prompt); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // }
import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.PropertyNotFoundException; import de.fesere.hypermedia.cj.model.data.BooleanDataEntry; import de.fesere.hypermedia.cj.model.data.NullDataEntry; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import java.net.URI; import java.util.*;
public void addData(DataEntry dataEntry) { data.add(dataEntry); } public List<DataEntry> getData() { return new ArrayList<>(data); } public List<Link> getLinks() { return links; } public String getString(String name) { DataEntry found = findDataEntry(name); if (found instanceof StringDataEntry) { return ((StringDataEntry) found).getValue(); } throw new PropertyNotFoundException(name, href, String.class); } public boolean isNullValue(String name) { DataEntry found = findDataEntry(name); return found instanceof NullDataEntry; } public int getInt(String name) { DataEntry found = findDataEntry(name);
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/PropertyNotFoundException.java // public class PropertyNotFoundException extends MalformedDataValueException { // public PropertyNotFoundException(String name, URI href, Class type) { // super("Did not find property '" + name + "' as " + type.getSimpleName() +" in " + href); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/BooleanDataEntry.java // public class BooleanDataEntry extends BaseDataEntry<Boolean> { // private final boolean value; // // public BooleanDataEntry(String name, boolean booleanValue, String prompt) { // super(name, prompt); // this.value = booleanValue; // } // // @Override // public Boolean getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NullDataEntry.java // public class NullDataEntry extends BaseDataEntry { // public NullDataEntry(String name, String prompt) { // super(name, prompt); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.PropertyNotFoundException; import de.fesere.hypermedia.cj.model.data.BooleanDataEntry; import de.fesere.hypermedia.cj.model.data.NullDataEntry; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import java.net.URI; import java.util.*; public void addData(DataEntry dataEntry) { data.add(dataEntry); } public List<DataEntry> getData() { return new ArrayList<>(data); } public List<Link> getLinks() { return links; } public String getString(String name) { DataEntry found = findDataEntry(name); if (found instanceof StringDataEntry) { return ((StringDataEntry) found).getValue(); } throw new PropertyNotFoundException(name, href, String.class); } public boolean isNullValue(String name) { DataEntry found = findDataEntry(name); return found instanceof NullDataEntry; } public int getInt(String name) { DataEntry found = findDataEntry(name);
if (found instanceof NumberDataEntry) {
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Item.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/PropertyNotFoundException.java // public class PropertyNotFoundException extends MalformedDataValueException { // public PropertyNotFoundException(String name, URI href, Class type) { // super("Did not find property '" + name + "' as " + type.getSimpleName() +" in " + href); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/BooleanDataEntry.java // public class BooleanDataEntry extends BaseDataEntry<Boolean> { // private final boolean value; // // public BooleanDataEntry(String name, boolean booleanValue, String prompt) { // super(name, prompt); // this.value = booleanValue; // } // // @Override // public Boolean getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NullDataEntry.java // public class NullDataEntry extends BaseDataEntry { // public NullDataEntry(String name, String prompt) { // super(name, prompt); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // }
import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.PropertyNotFoundException; import de.fesere.hypermedia.cj.model.data.BooleanDataEntry; import de.fesere.hypermedia.cj.model.data.NullDataEntry; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import java.net.URI; import java.util.*;
DataEntry found = findDataEntry(name); return found instanceof NullDataEntry; } public int getInt(String name) { DataEntry found = findDataEntry(name); if (found instanceof NumberDataEntry) { Number value = ((NumberDataEntry) found).getValue(); return Integer.parseInt(value.toString()); } throw new PropertyNotFoundException(name, href, Number.class); } public double getDouble(String name) { DataEntry found = findDataEntry(name); if (found instanceof NumberDataEntry) { Number value = ((NumberDataEntry) found).getValue(); return Double.parseDouble(value.toString()); } throw new PropertyNotFoundException(name, href, Number.class); } public boolean getBoolean(String name) { DataEntry entry = findDataEntry(name);
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/PropertyNotFoundException.java // public class PropertyNotFoundException extends MalformedDataValueException { // public PropertyNotFoundException(String name, URI href, Class type) { // super("Did not find property '" + name + "' as " + type.getSimpleName() +" in " + href); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/BooleanDataEntry.java // public class BooleanDataEntry extends BaseDataEntry<Boolean> { // private final boolean value; // // public BooleanDataEntry(String name, boolean booleanValue, String prompt) { // super(name, prompt); // this.value = booleanValue; // } // // @Override // public Boolean getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NullDataEntry.java // public class NullDataEntry extends BaseDataEntry { // public NullDataEntry(String name, String prompt) { // super(name, prompt); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.PropertyNotFoundException; import de.fesere.hypermedia.cj.model.data.BooleanDataEntry; import de.fesere.hypermedia.cj.model.data.NullDataEntry; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import java.net.URI; import java.util.*; DataEntry found = findDataEntry(name); return found instanceof NullDataEntry; } public int getInt(String name) { DataEntry found = findDataEntry(name); if (found instanceof NumberDataEntry) { Number value = ((NumberDataEntry) found).getValue(); return Integer.parseInt(value.toString()); } throw new PropertyNotFoundException(name, href, Number.class); } public double getDouble(String name) { DataEntry found = findDataEntry(name); if (found instanceof NumberDataEntry) { Number value = ((NumberDataEntry) found).getValue(); return Double.parseDouble(value.toString()); } throw new PropertyNotFoundException(name, href, Number.class); } public boolean getBoolean(String name) { DataEntry entry = findDataEntry(name);
if (entry instanceof BooleanDataEntry) {
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/Item.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/PropertyNotFoundException.java // public class PropertyNotFoundException extends MalformedDataValueException { // public PropertyNotFoundException(String name, URI href, Class type) { // super("Did not find property '" + name + "' as " + type.getSimpleName() +" in " + href); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/BooleanDataEntry.java // public class BooleanDataEntry extends BaseDataEntry<Boolean> { // private final boolean value; // // public BooleanDataEntry(String name, boolean booleanValue, String prompt) { // super(name, prompt); // this.value = booleanValue; // } // // @Override // public Boolean getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NullDataEntry.java // public class NullDataEntry extends BaseDataEntry { // public NullDataEntry(String name, String prompt) { // super(name, prompt); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // }
import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.PropertyNotFoundException; import de.fesere.hypermedia.cj.model.data.BooleanDataEntry; import de.fesere.hypermedia.cj.model.data.NullDataEntry; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import java.net.URI; import java.util.*;
public double getDouble(String name) { DataEntry found = findDataEntry(name); if (found instanceof NumberDataEntry) { Number value = ((NumberDataEntry) found).getValue(); return Double.parseDouble(value.toString()); } throw new PropertyNotFoundException(name, href, Number.class); } public boolean getBoolean(String name) { DataEntry entry = findDataEntry(name); if (entry instanceof BooleanDataEntry) { return (boolean) entry.getValue(); } throw new PropertyNotFoundException(name, href, Boolean.class); } private DataEntry findDataEntry(String name) { DataEntry found = null; for (DataEntry entry : data) { if (entry.getName().equals(name)) { found = entry; break; } } if (found == null) {
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/ElementNotFoundException.java // public class ElementNotFoundException extends RuntimeException { // public ElementNotFoundException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/PropertyNotFoundException.java // public class PropertyNotFoundException extends MalformedDataValueException { // public PropertyNotFoundException(String name, URI href, Class type) { // super("Did not find property '" + name + "' as " + type.getSimpleName() +" in " + href); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/BooleanDataEntry.java // public class BooleanDataEntry extends BaseDataEntry<Boolean> { // private final boolean value; // // public BooleanDataEntry(String name, boolean booleanValue, String prompt) { // super(name, prompt); // this.value = booleanValue; // } // // @Override // public Boolean getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NullDataEntry.java // public class NullDataEntry extends BaseDataEntry { // public NullDataEntry(String name, String prompt) { // super(name, prompt); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/NumberDataEntry.java // public class NumberDataEntry extends BaseDataEntry<Number> { // // private Number value; // // public NumberDataEntry(String name, Number value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public Number getValue() { // return value; // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/data/StringDataEntry.java // public class StringDataEntry extends BaseDataEntry<String> { // // private String value; // // public StringDataEntry(String name) { // this(name, ""); // } // // public StringDataEntry(String name, String value) { // super(name); // this.value = value; // } // // public StringDataEntry(String name, String value, String prompt) { // super(name, prompt); // this.value = value; // } // // @Override // public String getValue() { // return value; // } // } // Path: src/main/java/de/fesere/hypermedia/cj/model/Item.java import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import de.fesere.hypermedia.cj.exceptions.ElementNotFoundException; import de.fesere.hypermedia.cj.exceptions.PropertyNotFoundException; import de.fesere.hypermedia.cj.model.data.BooleanDataEntry; import de.fesere.hypermedia.cj.model.data.NullDataEntry; import de.fesere.hypermedia.cj.model.data.NumberDataEntry; import de.fesere.hypermedia.cj.model.data.StringDataEntry; import java.net.URI; import java.util.*; public double getDouble(String name) { DataEntry found = findDataEntry(name); if (found instanceof NumberDataEntry) { Number value = ((NumberDataEntry) found).getValue(); return Double.parseDouble(value.toString()); } throw new PropertyNotFoundException(name, href, Number.class); } public boolean getBoolean(String name) { DataEntry entry = findDataEntry(name); if (entry instanceof BooleanDataEntry) { return (boolean) entry.getValue(); } throw new PropertyNotFoundException(name, href, Boolean.class); } private DataEntry findDataEntry(String name) { DataEntry found = null; for (DataEntry entry : data) { if (entry.getName().equals(name)) { found = entry; break; } } if (found == null) {
throw new ElementNotFoundException("Did not find property '" + name + "' in '" + href + "'");
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/MalformedDataValueException.java // public class MalformedDataValueException extends RuntimeException { // // public MalformedDataValueException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/SerializationException.java // public class SerializationException extends RuntimeException { // // public SerializationException(String message) { // super(message); // } // // public SerializationException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // }
import de.fesere.hypermedia.cj.exceptions.MalformedDataValueException; import de.fesere.hypermedia.cj.exceptions.SerializationException; import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.data.*; import org.apache.commons.lang3.StringUtils;
package de.fesere.hypermedia.cj.model.builder; public final class DataEntryFactory { public static DataEntry create(String name, Object value, String prompt) { if(StringUtils.isBlank(name)){ return createNone(); } if(value == null) {
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/MalformedDataValueException.java // public class MalformedDataValueException extends RuntimeException { // // public MalformedDataValueException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/SerializationException.java // public class SerializationException extends RuntimeException { // // public SerializationException(String message) { // super(message); // } // // public SerializationException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java import de.fesere.hypermedia.cj.exceptions.MalformedDataValueException; import de.fesere.hypermedia.cj.exceptions.SerializationException; import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.data.*; import org.apache.commons.lang3.StringUtils; package de.fesere.hypermedia.cj.model.builder; public final class DataEntryFactory { public static DataEntry create(String name, Object value, String prompt) { if(StringUtils.isBlank(name)){ return createNone(); } if(value == null) {
throw new MalformedDataValueException("value of '"+name+"' can not be null");
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/MalformedDataValueException.java // public class MalformedDataValueException extends RuntimeException { // // public MalformedDataValueException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/SerializationException.java // public class SerializationException extends RuntimeException { // // public SerializationException(String message) { // super(message); // } // // public SerializationException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // }
import de.fesere.hypermedia.cj.exceptions.MalformedDataValueException; import de.fesere.hypermedia.cj.exceptions.SerializationException; import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.data.*; import org.apache.commons.lang3.StringUtils;
package de.fesere.hypermedia.cj.model.builder; public final class DataEntryFactory { public static DataEntry create(String name, Object value, String prompt) { if(StringUtils.isBlank(name)){ return createNone(); } if(value == null) { throw new MalformedDataValueException("value of '"+name+"' can not be null"); } Class type = value.getClass(); if (TypeUtils.isString(type)) { return new StringDataEntry(name, (String) value, prompt); } else if (TypeUtils.isNumber(type)) { return new NumberDataEntry(name, (Number) value, prompt); } else if (TypeUtils.isBoolean(type)) { return new BooleanDataEntry(name, (Boolean) value, prompt); } else {
// Path: src/main/java/de/fesere/hypermedia/cj/exceptions/MalformedDataValueException.java // public class MalformedDataValueException extends RuntimeException { // // public MalformedDataValueException(String message) { // super(message); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/exceptions/SerializationException.java // public class SerializationException extends RuntimeException { // // public SerializationException(String message) { // super(message); // } // // public SerializationException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryFactory.java import de.fesere.hypermedia.cj.exceptions.MalformedDataValueException; import de.fesere.hypermedia.cj.exceptions.SerializationException; import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.data.*; import org.apache.commons.lang3.StringUtils; package de.fesere.hypermedia.cj.model.builder; public final class DataEntryFactory { public static DataEntry create(String name, Object value, String prompt) { if(StringUtils.isBlank(name)){ return createNone(); } if(value == null) { throw new MalformedDataValueException("value of '"+name+"' can not be null"); } Class type = value.getClass(); if (TypeUtils.isString(type)) { return new StringDataEntry(name, (String) value, prompt); } else if (TypeUtils.isNumber(type)) { return new NumberDataEntry(name, (Number) value, prompt); } else if (TypeUtils.isBoolean(type)) { return new BooleanDataEntry(name, (Boolean) value, prompt); } else {
throw new SerializationException("'"+name+"' of type " + type + " can not be converted to DataEntry");
felipesere/collection-json-parser
src/main/java/de/fesere/hypermedia/cj/serialization/DataEntryDeserializer.java
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryBuilder.java // public class DataEntryBuilder { // // private String name; // private String prompt = null; // private boolean writeNullValue = false; // // private Object value; // // public DataEntryBuilder setName(String name) { // this.name = name; // return this; // } // // public DataEntryBuilder setValue(Object value) { // this.value = value; // return this; // } // // public DataEntryBuilder setNullValue() { // writeNullValue = true; // return this; // } // // public DataEntryBuilder setPrompt(String prompt) { // this.prompt = prompt; // return this; // } // // public DataEntry build() { // if(writeNullValue) { // return DataEntryFactory.createNull(name, prompt); // } // // if(value == null) { // return DataEntryFactory.create(name, "", prompt); // } // // return DataEntryFactory.create(name, value, prompt); // // } // }
import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.builder.DataEntryBuilder; import java.io.IOException; import static com.fasterxml.jackson.core.JsonToken.*;
package de.fesere.hypermedia.cj.serialization; public class DataEntryDeserializer extends StdDeserializer<DataEntry> { public DataEntryDeserializer() { super(DataEntry.class); } @Override public DataEntry deserialize(JsonParser jParser, DeserializationContext ctxt) throws IOException {
// Path: src/main/java/de/fesere/hypermedia/cj/model/DataEntry.java // public interface DataEntry<T> { // String getName(); // // String getPrompt(); // // T getValue(); // // String buildQueryRepresentation(); // } // // Path: src/main/java/de/fesere/hypermedia/cj/model/builder/DataEntryBuilder.java // public class DataEntryBuilder { // // private String name; // private String prompt = null; // private boolean writeNullValue = false; // // private Object value; // // public DataEntryBuilder setName(String name) { // this.name = name; // return this; // } // // public DataEntryBuilder setValue(Object value) { // this.value = value; // return this; // } // // public DataEntryBuilder setNullValue() { // writeNullValue = true; // return this; // } // // public DataEntryBuilder setPrompt(String prompt) { // this.prompt = prompt; // return this; // } // // public DataEntry build() { // if(writeNullValue) { // return DataEntryFactory.createNull(name, prompt); // } // // if(value == null) { // return DataEntryFactory.create(name, "", prompt); // } // // return DataEntryFactory.create(name, value, prompt); // // } // } // Path: src/main/java/de/fesere/hypermedia/cj/serialization/DataEntryDeserializer.java import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import de.fesere.hypermedia.cj.model.DataEntry; import de.fesere.hypermedia.cj.model.builder.DataEntryBuilder; import java.io.IOException; import static com.fasterxml.jackson.core.JsonToken.*; package de.fesere.hypermedia.cj.serialization; public class DataEntryDeserializer extends StdDeserializer<DataEntry> { public DataEntryDeserializer() { super(DataEntry.class); } @Override public DataEntry deserialize(JsonParser jParser, DeserializationContext ctxt) throws IOException {
DataEntryBuilder builder = new DataEntryBuilder();
MovieNetwork/Wubble
app/src/main/java/com/proxima/Wubble/network/VolleySingleton.java
// Path: app/src/main/java/com/proxima/Wubble/AppGlobal.java // public class AppGlobal extends Application { // // private static AppGlobal sAppInstance; // // // @Override // public void onCreate() { // super.onCreate(); // sAppInstance = this; // } // // public static AppGlobal getInstance() { // return sAppInstance; // } // // public static Context getAppContext() { // return sAppInstance.getApplicationContext(); // } // // // } // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7";
import android.widget.Toast; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.JsonObjectRequest; import com.android.volley.toolbox.Volley; import com.proxima.Wubble.AppGlobal; import org.json.JSONObject; import static com.proxima.Wubble.Constants.TMDB_API_KEY;
package com.proxima.Wubble.network; /** * Created by Epokhe on 08.03.2015. */ public class VolleySingleton { private static VolleySingleton sInstance = null; private boolean isTransferComplete = true; private JSONObject mTMDBConfig; private RequestQueue mRequestQueue; private VolleySingleton() {
// Path: app/src/main/java/com/proxima/Wubble/AppGlobal.java // public class AppGlobal extends Application { // // private static AppGlobal sAppInstance; // // // @Override // public void onCreate() { // super.onCreate(); // sAppInstance = this; // } // // public static AppGlobal getInstance() { // return sAppInstance; // } // // public static Context getAppContext() { // return sAppInstance.getApplicationContext(); // } // // // } // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // Path: app/src/main/java/com/proxima/Wubble/network/VolleySingleton.java import android.widget.Toast; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.JsonObjectRequest; import com.android.volley.toolbox.Volley; import com.proxima.Wubble.AppGlobal; import org.json.JSONObject; import static com.proxima.Wubble.Constants.TMDB_API_KEY; package com.proxima.Wubble.network; /** * Created by Epokhe on 08.03.2015. */ public class VolleySingleton { private static VolleySingleton sInstance = null; private boolean isTransferComplete = true; private JSONObject mTMDBConfig; private RequestQueue mRequestQueue; private VolleySingleton() {
mRequestQueue = Volley.newRequestQueue(AppGlobal.getAppContext());
MovieNetwork/Wubble
app/src/main/java/com/proxima/Wubble/network/VolleySingleton.java
// Path: app/src/main/java/com/proxima/Wubble/AppGlobal.java // public class AppGlobal extends Application { // // private static AppGlobal sAppInstance; // // // @Override // public void onCreate() { // super.onCreate(); // sAppInstance = this; // } // // public static AppGlobal getInstance() { // return sAppInstance; // } // // public static Context getAppContext() { // return sAppInstance.getApplicationContext(); // } // // // } // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7";
import android.widget.Toast; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.JsonObjectRequest; import com.android.volley.toolbox.Volley; import com.proxima.Wubble.AppGlobal; import org.json.JSONObject; import static com.proxima.Wubble.Constants.TMDB_API_KEY;
package com.proxima.Wubble.network; /** * Created by Epokhe on 08.03.2015. */ public class VolleySingleton { private static VolleySingleton sInstance = null; private boolean isTransferComplete = true; private JSONObject mTMDBConfig; private RequestQueue mRequestQueue; private VolleySingleton() { mRequestQueue = Volley.newRequestQueue(AppGlobal.getAppContext());
// Path: app/src/main/java/com/proxima/Wubble/AppGlobal.java // public class AppGlobal extends Application { // // private static AppGlobal sAppInstance; // // // @Override // public void onCreate() { // super.onCreate(); // sAppInstance = this; // } // // public static AppGlobal getInstance() { // return sAppInstance; // } // // public static Context getAppContext() { // return sAppInstance.getApplicationContext(); // } // // // } // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // Path: app/src/main/java/com/proxima/Wubble/network/VolleySingleton.java import android.widget.Toast; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.JsonObjectRequest; import com.android.volley.toolbox.Volley; import com.proxima.Wubble.AppGlobal; import org.json.JSONObject; import static com.proxima.Wubble.Constants.TMDB_API_KEY; package com.proxima.Wubble.network; /** * Created by Epokhe on 08.03.2015. */ public class VolleySingleton { private static VolleySingleton sInstance = null; private boolean isTransferComplete = true; private JSONObject mTMDBConfig; private RequestQueue mRequestQueue; private VolleySingleton() { mRequestQueue = Volley.newRequestQueue(AppGlobal.getAppContext());
JsonObjectRequest configRequest = new JsonObjectRequest(Request.Method.GET, "http://api.themoviedb.org/3/configuration?api_key=" + TMDB_API_KEY, (JSONObject) null,
MovieNetwork/Wubble
app/src/main/java/com/proxima/Wubble/activities/SplashActivity.java
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String PARSE_APP_ID = "5Sqm8A6YXQ1heLwSU1dOvXTe6Gf026OoyowLbWNP"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String PARSE_CLIENT_KEY = "wRJsDUtcHiwgJjB3JzE3v0ViVabFnD5U7DaVMec2";
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import com.parse.Parse; import com.parse.ParseUser; import com.proxima.Wubble.R; import static com.proxima.Wubble.Constants.PARSE_APP_ID; import static com.proxima.Wubble.Constants.PARSE_CLIENT_KEY;
package com.proxima.Wubble.activities; public class SplashActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String PARSE_APP_ID = "5Sqm8A6YXQ1heLwSU1dOvXTe6Gf026OoyowLbWNP"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String PARSE_CLIENT_KEY = "wRJsDUtcHiwgJjB3JzE3v0ViVabFnD5U7DaVMec2"; // Path: app/src/main/java/com/proxima/Wubble/activities/SplashActivity.java import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import com.parse.Parse; import com.parse.ParseUser; import com.proxima.Wubble.R; import static com.proxima.Wubble.Constants.PARSE_APP_ID; import static com.proxima.Wubble.Constants.PARSE_CLIENT_KEY; package com.proxima.Wubble.activities; public class SplashActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
Parse.initialize(this, PARSE_APP_ID, PARSE_CLIENT_KEY);
MovieNetwork/Wubble
app/src/main/java/com/proxima/Wubble/activities/SplashActivity.java
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String PARSE_APP_ID = "5Sqm8A6YXQ1heLwSU1dOvXTe6Gf026OoyowLbWNP"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String PARSE_CLIENT_KEY = "wRJsDUtcHiwgJjB3JzE3v0ViVabFnD5U7DaVMec2";
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import com.parse.Parse; import com.parse.ParseUser; import com.proxima.Wubble.R; import static com.proxima.Wubble.Constants.PARSE_APP_ID; import static com.proxima.Wubble.Constants.PARSE_CLIENT_KEY;
package com.proxima.Wubble.activities; public class SplashActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String PARSE_APP_ID = "5Sqm8A6YXQ1heLwSU1dOvXTe6Gf026OoyowLbWNP"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String PARSE_CLIENT_KEY = "wRJsDUtcHiwgJjB3JzE3v0ViVabFnD5U7DaVMec2"; // Path: app/src/main/java/com/proxima/Wubble/activities/SplashActivity.java import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import com.parse.Parse; import com.parse.ParseUser; import com.proxima.Wubble.R; import static com.proxima.Wubble.Constants.PARSE_APP_ID; import static com.proxima.Wubble.Constants.PARSE_CLIENT_KEY; package com.proxima.Wubble.activities; public class SplashActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
Parse.initialize(this, PARSE_APP_ID, PARSE_CLIENT_KEY);
MovieNetwork/Wubble
app/src/main/java/com/proxima/Wubble/URLBuilder.java
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92";
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT;
package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url =
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92"; // Path: app/src/main/java/com/proxima/Wubble/URLBuilder.java import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT; package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url =
TMDB_API_URL_BASE +
MovieNetwork/Wubble
app/src/main/java/com/proxima/Wubble/URLBuilder.java
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92";
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT;
package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url = TMDB_API_URL_BASE +
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92"; // Path: app/src/main/java/com/proxima/Wubble/URLBuilder.java import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT; package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url = TMDB_API_URL_BASE +
TMDB_API_URL_MOVIE +
MovieNetwork/Wubble
app/src/main/java/com/proxima/Wubble/URLBuilder.java
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92";
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT;
package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url = TMDB_API_URL_BASE + TMDB_API_URL_MOVIE + Integer.toString(movieId) + "?" +
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92"; // Path: app/src/main/java/com/proxima/Wubble/URLBuilder.java import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT; package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url = TMDB_API_URL_BASE + TMDB_API_URL_MOVIE + Integer.toString(movieId) + "?" +
TMDB_API_URL_API +
MovieNetwork/Wubble
app/src/main/java/com/proxima/Wubble/URLBuilder.java
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92";
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT;
package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url = TMDB_API_URL_BASE + TMDB_API_URL_MOVIE + Integer.toString(movieId) + "?" + TMDB_API_URL_API +
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92"; // Path: app/src/main/java/com/proxima/Wubble/URLBuilder.java import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT; package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url = TMDB_API_URL_BASE + TMDB_API_URL_MOVIE + Integer.toString(movieId) + "?" + TMDB_API_URL_API +
TMDB_API_KEY;
MovieNetwork/Wubble
app/src/main/java/com/proxima/Wubble/URLBuilder.java
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92";
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT;
package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url = TMDB_API_URL_BASE + TMDB_API_URL_MOVIE + Integer.toString(movieId) + "?" + TMDB_API_URL_API + TMDB_API_KEY; return url; } public static String getMovieSearchURL(String movieTitle) throws UnsupportedEncodingException { String url = TMDB_API_URL_BASE +
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92"; // Path: app/src/main/java/com/proxima/Wubble/URLBuilder.java import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT; package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url = TMDB_API_URL_BASE + TMDB_API_URL_MOVIE + Integer.toString(movieId) + "?" + TMDB_API_URL_API + TMDB_API_KEY; return url; } public static String getMovieSearchURL(String movieTitle) throws UnsupportedEncodingException { String url = TMDB_API_URL_BASE +
TMDB_API_URL_SEARCH +
MovieNetwork/Wubble
app/src/main/java/com/proxima/Wubble/URLBuilder.java
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92";
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT;
package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url = TMDB_API_URL_BASE + TMDB_API_URL_MOVIE + Integer.toString(movieId) + "?" + TMDB_API_URL_API + TMDB_API_KEY; return url; } public static String getMovieSearchURL(String movieTitle) throws UnsupportedEncodingException { String url = TMDB_API_URL_BASE + TMDB_API_URL_SEARCH + "?" + TMDB_API_URL_API + TMDB_API_KEY + "&" +
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92"; // Path: app/src/main/java/com/proxima/Wubble/URLBuilder.java import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT; package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url = TMDB_API_URL_BASE + TMDB_API_URL_MOVIE + Integer.toString(movieId) + "?" + TMDB_API_URL_API + TMDB_API_KEY; return url; } public static String getMovieSearchURL(String movieTitle) throws UnsupportedEncodingException { String url = TMDB_API_URL_BASE + TMDB_API_URL_SEARCH + "?" + TMDB_API_URL_API + TMDB_API_KEY + "&" +
TMDB_API_URL_QUERY +
MovieNetwork/Wubble
app/src/main/java/com/proxima/Wubble/URLBuilder.java
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92";
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT;
package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url = TMDB_API_URL_BASE + TMDB_API_URL_MOVIE + Integer.toString(movieId) + "?" + TMDB_API_URL_API + TMDB_API_KEY; return url; } public static String getMovieSearchURL(String movieTitle) throws UnsupportedEncodingException { String url = TMDB_API_URL_BASE + TMDB_API_URL_SEARCH + "?" + TMDB_API_URL_API + TMDB_API_KEY + "&" + TMDB_API_URL_QUERY + URLEncoder.encode(movieTitle, "UTF-8"); return url; } public static String getImageURL(String path) { String url =
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92"; // Path: app/src/main/java/com/proxima/Wubble/URLBuilder.java import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT; package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url = TMDB_API_URL_BASE + TMDB_API_URL_MOVIE + Integer.toString(movieId) + "?" + TMDB_API_URL_API + TMDB_API_KEY; return url; } public static String getMovieSearchURL(String movieTitle) throws UnsupportedEncodingException { String url = TMDB_API_URL_BASE + TMDB_API_URL_SEARCH + "?" + TMDB_API_URL_API + TMDB_API_KEY + "&" + TMDB_API_URL_QUERY + URLEncoder.encode(movieTitle, "UTF-8"); return url; } public static String getImageURL(String path) { String url =
TMDB_IMAGE_BASE_URL +
MovieNetwork/Wubble
app/src/main/java/com/proxima/Wubble/URLBuilder.java
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92";
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT;
package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url = TMDB_API_URL_BASE + TMDB_API_URL_MOVIE + Integer.toString(movieId) + "?" + TMDB_API_URL_API + TMDB_API_KEY; return url; } public static String getMovieSearchURL(String movieTitle) throws UnsupportedEncodingException { String url = TMDB_API_URL_BASE + TMDB_API_URL_SEARCH + "?" + TMDB_API_URL_API + TMDB_API_KEY + "&" + TMDB_API_URL_QUERY + URLEncoder.encode(movieTitle, "UTF-8"); return url; } public static String getImageURL(String path) { String url = TMDB_IMAGE_BASE_URL +
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92"; // Path: app/src/main/java/com/proxima/Wubble/URLBuilder.java import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT; package com.proxima.Wubble; /** * Created by Epokhe on 10.03.2015. */ public class URLBuilder { public static String getMovieWithIdURL(int movieId) { String url = TMDB_API_URL_BASE + TMDB_API_URL_MOVIE + Integer.toString(movieId) + "?" + TMDB_API_URL_API + TMDB_API_KEY; return url; } public static String getMovieSearchURL(String movieTitle) throws UnsupportedEncodingException { String url = TMDB_API_URL_BASE + TMDB_API_URL_SEARCH + "?" + TMDB_API_URL_API + TMDB_API_KEY + "&" + TMDB_API_URL_QUERY + URLEncoder.encode(movieTitle, "UTF-8"); return url; } public static String getImageURL(String path) { String url = TMDB_IMAGE_BASE_URL +
TMDB_POSTER_SIZE_DEFAULT +
MovieNetwork/Wubble
app/src/main/java/com/proxima/Wubble/URLBuilder.java
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92";
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT;
TMDB_API_URL_API + TMDB_API_KEY; return url; } public static String getMovieSearchURL(String movieTitle) throws UnsupportedEncodingException { String url = TMDB_API_URL_BASE + TMDB_API_URL_SEARCH + "?" + TMDB_API_URL_API + TMDB_API_KEY + "&" + TMDB_API_URL_QUERY + URLEncoder.encode(movieTitle, "UTF-8"); return url; } public static String getImageURL(String path) { String url = TMDB_IMAGE_BASE_URL + TMDB_POSTER_SIZE_DEFAULT + path; return url; } public static String getUpcomingMoviesURL() { String url = TMDB_API_URL_BASE + TMDB_API_URL_MOVIE +
// Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_BASE_URL = "http://www.omdbapi.com/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_IMDB_ID = "i="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_PLOT = "plot=short"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String OMDB_R = "r=json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API = "apikey="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_API_KEY = "jt33c9zrw6u7keppu32pc9vj"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_BASE_URL = "http://api.rottentomatoes.com/api/public/v1.0/movie_alias.json"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_IMDB_ID = "id="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String ROTTEN_TOMATOES_TYPE_IMDB = "type=imdb"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_KEY = "dc7176817ac527fc0d4f384f311f1cb7"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_API = "api_key="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_BASE = "http://api.themoviedb.org/3/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_MOVIE = "movie/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_QUERY = "query="; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_SEARCH = "search/movie"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_API_URL_UPCOMING = "upcoming"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_IMAGE_BASE_URL = "http://image.tmdb.org/t/p/"; // // Path: app/src/main/java/com/proxima/Wubble/Constants.java // public static final String TMDB_POSTER_SIZE_DEFAULT = "w92"; // Path: app/src/main/java/com/proxima/Wubble/URLBuilder.java import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static com.proxima.Wubble.Constants.OMDB_BASE_URL; import static com.proxima.Wubble.Constants.OMDB_IMDB_ID; import static com.proxima.Wubble.Constants.OMDB_PLOT; import static com.proxima.Wubble.Constants.OMDB_R; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_API_KEY; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_BASE_URL; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_IMDB_ID; import static com.proxima.Wubble.Constants.ROTTEN_TOMATOES_TYPE_IMDB; import static com.proxima.Wubble.Constants.TMDB_API_KEY; import static com.proxima.Wubble.Constants.TMDB_API_URL_API; import static com.proxima.Wubble.Constants.TMDB_API_URL_BASE; import static com.proxima.Wubble.Constants.TMDB_API_URL_MOVIE; import static com.proxima.Wubble.Constants.TMDB_API_URL_QUERY; import static com.proxima.Wubble.Constants.TMDB_API_URL_SEARCH; import static com.proxima.Wubble.Constants.TMDB_API_URL_UPCOMING; import static com.proxima.Wubble.Constants.TMDB_IMAGE_BASE_URL; import static com.proxima.Wubble.Constants.TMDB_POSTER_SIZE_DEFAULT; TMDB_API_URL_API + TMDB_API_KEY; return url; } public static String getMovieSearchURL(String movieTitle) throws UnsupportedEncodingException { String url = TMDB_API_URL_BASE + TMDB_API_URL_SEARCH + "?" + TMDB_API_URL_API + TMDB_API_KEY + "&" + TMDB_API_URL_QUERY + URLEncoder.encode(movieTitle, "UTF-8"); return url; } public static String getImageURL(String path) { String url = TMDB_IMAGE_BASE_URL + TMDB_POSTER_SIZE_DEFAULT + path; return url; } public static String getUpcomingMoviesURL() { String url = TMDB_API_URL_BASE + TMDB_API_URL_MOVIE +
TMDB_API_URL_UPCOMING +