Skip to content

Commit

Permalink
support initial load where clause
Browse files Browse the repository at this point in the history
  • Loading branch information
wernerdaehn committed Aug 28, 2022
1 parent 4d60dd8 commit 9fe8d0a
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 108 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.rtdi.bigdata.connector</groupId>
<artifactId>s4hanaconnector</artifactId>
<version>0.9.35</version>
<version>0.9.36</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<io.rtdi.bigdata.connector.version>0.10.16</io.rtdi.bigdata.connector.version>
<io.rtdi.bigdata.connector.version>0.10.18</io.rtdi.bigdata.connector.version>
</properties>
<build>
<finalName>${project.artifactId}</finalName>
Expand Down Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>com.sap.cloud.db.jdbc</groupId>
<artifactId>ngdbc</artifactId>
<version>2.11.14</version>
<version>2.13.9</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public static class TableImport {
private String tablename;
private String schemaname;
private boolean imported;
private String initialloadwhere;

public TableImport() {
super();
Expand Down Expand Up @@ -140,6 +141,14 @@ public String getSchemaname() {
public void setSchemaname(String schemaname) {
this.schemaname = schemaname;
}

public String getInitialloadwhere() {
return initialloadwhere;
}

public void setInitialloadwhere(String initialloadwhere) {
this.initialloadwhere = initialloadwhere;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,21 @@ public class S4HanaTableMapping {
private String name;
private String deltaselect;
private StringBuffer initialselectprojection;
private String initialloadwhere;

public S4HanaTableMapping() {
super();
}

public S4HanaTableMapping(String name, String username, String sourcedbschema, String mastertable, String alias, Connection conn) throws ConnectorRuntimeException {
public S4HanaTableMapping(String name, String username, String sourcedbschema, String mastertable, String alias, String initialloadwhere, Connection conn) throws ConnectorRuntimeException {
super();
this.mastertable = mastertable;
this.alias = alias;
this.sourcedbschema = sourcedbschema;
this.username = username;
this.conn = conn;
this.name = name;
this.initialloadwhere = initialloadwhere;
addColumns();
}

Expand Down Expand Up @@ -248,6 +250,7 @@ protected void parseValues(S4HanaTableMapping data) throws ConnectorRuntimeExcep
this.columnmappings = data.getColumnmappings();
this.pkcolumns = data.getPKColumns();
this.alias = data.getAlias();
this.initialloadwhere = data.getInitialloadwhere();
}

public void setMastertable(String mastertable) {
Expand Down Expand Up @@ -751,6 +754,9 @@ public String getInitialSelect(Integer partition) {
select.append(") ");
}
select.append(" as ").append(getAliasIdentifier());
if (initialloadwhere != null) {
select.append(" where ").append(initialloadwhere);
}
return select.toString();
}

Expand All @@ -759,5 +765,13 @@ public String toString() {
return mastertable;
}

public String getInitialloadwhere() {
return initialloadwhere;
}

public void setInitialloadwhere(String initialloadwhere) {
this.initialloadwhere = initialloadwhere;
}


}
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
package io.rtdi.bigdata.s4hanaconnector.rest;

import java.util.List;

import jakarta.annotation.security.RolesAllowed;
import jakarta.servlet.ServletContext;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Configuration;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import io.rtdi.bigdata.connector.connectorframework.WebAppController;
import io.rtdi.bigdata.connector.connectorframework.controller.ConnectionController;
import io.rtdi.bigdata.connector.connectorframework.controller.ConnectorController;
import io.rtdi.bigdata.connector.connectorframework.rest.JAXBErrorResponseBuilder;
import io.rtdi.bigdata.connector.connectorframework.rest.JAXBSuccessResponseBuilder;
import io.rtdi.bigdata.connector.connectorframework.servlet.ServletSecurityConstants;
import io.rtdi.bigdata.s4hanaconnector.S4HanaTableMapping;
import io.rtdi.bigdata.s4hanaconnector.S4HanaBrowse;
import io.rtdi.bigdata.s4hanaconnector.S4HanaBrowse.TableImport;
import io.rtdi.bigdata.s4hanaconnector.S4HanaConnectionProperties;

@Path("/")
public class SourceTableService {
@Context
private Configuration configuration;

@Context
private ServletContext servletContext;

public SourceTableService() {
}

@GET
@Path("/connections/{connectionname}/sourcetables")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ServletSecurityConstants.ROLE_VIEW})
public Response getFiles(@PathParam("connectionname") String connectionname, @PathParam("name") String name) {
try {
ConnectorController connector = WebAppController.getConnectorOrFail(servletContext);
ConnectionController connection = connector.getConnectionOrFail(connectionname);
S4HanaBrowse browser = (S4HanaBrowse) connection.getBrowser();
return Response.ok(browser.getHanaTables()).build();
} catch (Exception e) {
return JAXBErrorResponseBuilder.getJAXBResponse(e);
}
}

@POST
@Path("/connections/{connectionname}/sourcetables")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ServletSecurityConstants.ROLE_VIEW})
public Response getFiles(@PathParam("connectionname") String connectionname, List<TableImport> data) {
try {
ConnectorController connector = WebAppController.getConnectorOrFail(servletContext);
ConnectionController connection = connector.getConnectionOrFail(connectionname);
S4HanaConnectionProperties props = (S4HanaConnectionProperties) connection.getConnectionProperties();
String dbuser = props.getUsername();
String dbschema = props.getSourceSchema();
S4HanaBrowse browser = (S4HanaBrowse) connection.getBrowser();
for (TableImport t : data) {
S4HanaTableMapping entity = new S4HanaTableMapping(t.getSchemaname(), dbuser, dbschema, t.getTablename(), "L1", browser.getConnection());
entity.write(browser.getBusinessObjectDirectory());
}
return JAXBSuccessResponseBuilder.getJAXBResponse("Saved " + data.size() + " table schemas");
} catch (Exception e) {
return JAXBErrorResponseBuilder.getJAXBResponse(e);
}
}

package io.rtdi.bigdata.s4hanaconnector.rest;

import java.util.List;

import jakarta.annotation.security.RolesAllowed;
import jakarta.servlet.ServletContext;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Configuration;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import io.rtdi.bigdata.connector.connectorframework.WebAppController;
import io.rtdi.bigdata.connector.connectorframework.controller.ConnectionController;
import io.rtdi.bigdata.connector.connectorframework.controller.ConnectorController;
import io.rtdi.bigdata.connector.connectorframework.rest.JAXBErrorResponseBuilder;
import io.rtdi.bigdata.connector.connectorframework.rest.JAXBSuccessResponseBuilder;
import io.rtdi.bigdata.connector.connectorframework.servlet.ServletSecurityConstants;
import io.rtdi.bigdata.s4hanaconnector.S4HanaTableMapping;
import io.rtdi.bigdata.s4hanaconnector.S4HanaBrowse;
import io.rtdi.bigdata.s4hanaconnector.S4HanaBrowse.TableImport;
import io.rtdi.bigdata.s4hanaconnector.S4HanaConnectionProperties;

@Path("/")
public class SourceTableService {
@Context
private Configuration configuration;

@Context
private ServletContext servletContext;

public SourceTableService() {
}

@GET
@Path("/connections/{connectionname}/sourcetables")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ServletSecurityConstants.ROLE_VIEW})
public Response getFiles(@PathParam("connectionname") String connectionname, @PathParam("name") String name) {
try {
ConnectorController connector = WebAppController.getConnectorOrFail(servletContext);
ConnectionController connection = connector.getConnectionOrFail(connectionname);
S4HanaBrowse browser = (S4HanaBrowse) connection.getBrowser();
return Response.ok(browser.getHanaTables()).build();
} catch (Exception e) {
return JAXBErrorResponseBuilder.getJAXBResponse(e);
}
}

@POST
@Path("/connections/{connectionname}/sourcetables")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ServletSecurityConstants.ROLE_VIEW})
public Response getFiles(@PathParam("connectionname") String connectionname, List<TableImport> data) {
try {
ConnectorController connector = WebAppController.getConnectorOrFail(servletContext);
ConnectionController connection = connector.getConnectionOrFail(connectionname);
S4HanaConnectionProperties props = (S4HanaConnectionProperties) connection.getConnectionProperties();
String dbuser = props.getUsername();
String dbschema = props.getSourceSchema();
S4HanaBrowse browser = (S4HanaBrowse) connection.getBrowser();
for (TableImport t : data) {
S4HanaTableMapping entity = new S4HanaTableMapping(t.getSchemaname(), dbuser, dbschema, t.getTablename(), "L1", t.getInitialloadwhere(), browser.getConnection());
entity.write(browser.getBusinessObjectDirectory());
}
return JAXBSuccessResponseBuilder.getJAXBResponse("Saved " + data.size() + " table schemas");
} catch (Exception e) {
return JAXBErrorResponseBuilder.getJAXBResponse(e);
}
}

}
64 changes: 35 additions & 29 deletions src/main/resources/ui5/view/AddTables.view
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@

<t:Table
id="SourceTables"
rows="{source>/}"
visibleRowCountMode="Auto"
selectionMode="None"
enableBusyIndicator="true"
enableSelectAll="false"
ariaLabelledBy="title">
<t:columns>
<t:Column width="50px">
<t:template>
<CheckBox selected="{source>imported}" />
</t:template>
</t:Column>
<t:Column filterProperty="tablename" >
<Label text="Table name (Click to Filter)"/>
<t:template>
<Text text="{source>tablename}" wrapping="false" renderWhitespace="false" />
</t:template>
</t:Column>
<t:Column >
<Label text="Schema name"/>
<t:template>
<Input value="{source>schemaname}" />
</t:template>
</t:Column>
</t:columns>
</t:Table>

<t:Table
id="SourceTables"
rows="{source>/}"
visibleRowCountMode="Auto"
selectionMode="None"
enableBusyIndicator="true"
enableSelectAll="false"
ariaLabelledBy="title">
<t:columns>
<t:Column width="50px">
<t:template>
<CheckBox selected="{source>imported}" />
</t:template>
</t:Column>
<t:Column filterProperty="tablename" >
<Label text="Table name (Click to Filter)"/>
<t:template>
<Text text="{source>tablename}" wrapping="false" renderWhitespace="false" />
</t:template>
</t:Column>
<t:Column >
<Label text="Schema name"/>
<t:template>
<Input value="{source>schemaname}" />
</t:template>
</t:Column>
<t:Column >
<Label text="Initial Load where clause"/>
<t:template>
<Input value="{source>initialloadwhere}" />
</t:template>
</t:Column>
</t:columns>
</t:Table>
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void setUp() throws Exception {
connprops.getSourceSchema(),
TABLENAME,
"L1",
connprops.getSourceSchema(),
browser.getConnection());
entity.write(browser.getBusinessObjectDirectory());
logger.info("setup of environment is completed");
Expand Down

0 comments on commit 9fe8d0a

Please sign in to comment.