Skip to content

Commit

Permalink
Merge pull request #9 from RespectNetwork/sandbox-sdk-csp
Browse files Browse the repository at this point in the history
Made DOB optional. Added born before and after date for dependent.
  • Loading branch information
kvats committed Feb 19, 2016
2 parents 9c6eb58 + 6e46011 commit 8e934e9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 23 deletions.
52 changes: 37 additions & 15 deletions src/main/java/net/respectnetwork/sdk/csp/BasicCSP.java
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,8 @@ private void prepareMessageToCloud(Message message, CloudNumber cloudNumber, Str
* {@inheritDoc}
*/
public void setGuardianshipInCloud(CSPInformation cspInformation, CloudNumber guardian,
CloudNumber dependent, Date dependentBirthDate, boolean withConsent, String secretToken, PrivateKey guardianPrivateSigningKey, String dependentToken)
CloudNumber dependent, Date dependentBirthDate, boolean withConsent, Date bornBeforeDate,
Date bornAfterDate, String secretToken, PrivateKey guardianPrivateSigningKey, String dependentToken)
throws Xdi2ClientException {

// Prepare message to guardian Cloud
Expand Down Expand Up @@ -1291,7 +1292,8 @@ public void setGuardianshipInCloud(CSPInformation cspInformation, CloudNumber gu


//Generating and Adding Dependent Statements
List<XDIStatement> dependentStatements = createDependentXDIStatements( guardian, dependent, dependentBirthDate, guardianPrivateSigningKey);
List<XDIStatement> dependentStatements = createDependentXDIStatements( guardian, dependent, dependentBirthDate, bornBeforeDate,
bornAfterDate, guardianPrivateSigningKey);
targetStatements2.addAll(dependentStatements);


Expand Down Expand Up @@ -1346,7 +1348,8 @@ public void setGuardianshipInCloud(CSPInformation cspInformation, CloudNumber gu
* {@inheritDoc}
*/
public void setGuardianshipInCSP(CSPInformation cspInformation, CloudNumber guardian,
CloudNumber dependent, Date dependentBirthDate, boolean withConsent, PrivateKey guardianPrivateSigningKey)
CloudNumber dependent, Date dependentBirthDate, boolean withConsent, Date bornBeforeDate,
Date bornAfterDate, PrivateKey guardianPrivateSigningKey)
throws Xdi2ClientException {

// Prepare message to Guardian Sub Graph in CSP Graph
Expand All @@ -1367,7 +1370,8 @@ public void setGuardianshipInCSP(CSPInformation cspInformation, CloudNumber guar


//Generating and Adding Dependent Statements
List<XDIStatement> dependentStatements = createDependentXDIStatements(guardian, dependent, dependentBirthDate, guardianPrivateSigningKey);
List<XDIStatement> dependentStatements = createDependentXDIStatements(guardian, dependent, dependentBirthDate, bornBeforeDate,
bornAfterDate, guardianPrivateSigningKey);
targetStatements.addAll(dependentStatements);


Expand Down Expand Up @@ -1420,7 +1424,7 @@ public void setGuardianshipInRN(CSPInformation cspInformation, CloudNumber guard


//Generating and Adding Dependent Statements
List<XDIStatement> dependentStatements = createDependentXDIStatements( guardian, dependent, dependentBirthDate, guardianPrivateSigningKey);
List<XDIStatement> dependentStatements = createDependentXDIStatements( guardian, dependent, dependentBirthDate, null, null, guardianPrivateSigningKey);
targetStatements.addAll(dependentStatements);

if (withConsent) {
Expand Down Expand Up @@ -1629,7 +1633,7 @@ private List<XDIStatement> createConsentXDIStatements(CloudNumber guardian, Clou
* @param signingKey
* @return XDIStatements
*/
private List<XDIStatement> createDependentXDIStatements(CloudNumber guardian, CloudNumber dependent, Date dependentBirthDate, PrivateKey signingKey) {
private List<XDIStatement> createDependentXDIStatements(CloudNumber guardian, CloudNumber dependent, Date dependentBirthDate, Date bornBeforeDate, Date bornAfterDate, PrivateKey signingKey) {


XDIArc innerGraph = XDIArc.create("(" + dependent.getXDIAddress() +"/#guardian" + ")");
Expand Down Expand Up @@ -1660,15 +1664,33 @@ private List<XDIStatement> createDependentXDIStatements(CloudNumber guardian, Cl

//Adding Date to Dependent's SubGraph
//[=]!:uuid:3333<#birth><$t>&/&/"2000-04-10T22:22:22Z")

String xdiDOBFormat = Timestamps.timestampToString(dependentBirthDate);
XDIStatement dobStatement = XDIStatement.fromLiteralComponents(
XDIAddressUtil.concatXDIAddresses(dependent.getXDIAddress(), XDIAddress.create("<#birth><$t>")),
xdiDOBFormat);

g.setStatement(dobStatement);


if(dependentBirthDate != null) {
String xdiDOBFormat = Timestamps.timestampToString(dependentBirthDate);
XDIStatement dobStatement = XDIStatement.fromLiteralComponents(
XDIAddressUtil.concatXDIAddresses(dependent.getXDIAddress(), XDIAddress.create("<#birth><$t>")),
xdiDOBFormat);

g.setStatement(dobStatement);
}
// Born before date
if(bornBeforeDate != null) {
String xdiBBAFormat = Timestamps.timestampToString(bornBeforeDate);
XDIStatement bbaStatement = XDIStatement.fromLiteralComponents(
XDIAddressUtil.concatXDIAddresses(dependent.getXDIAddress(), XDIAddress.create("<#born><#before><$t>")),
xdiBBAFormat);

g.setStatement(bbaStatement);
}

// Born after date
if(bornAfterDate != null) {
String xdiBADFormat = Timestamps.timestampToString(bornAfterDate);
XDIStatement badStatement = XDIStatement.fromLiteralComponents(
XDIAddressUtil.concatXDIAddresses(dependent.getXDIAddress(), XDIAddress.create("<#born><#after><$t>")),
xdiBADFormat);

g.setStatement(badStatement);
}
//Sign the Context: ([=]!:uuid:3333/#guardian)[<$sig>]<[=]!:uuid:6666>&/&/”...”
ContextNode signingNode = g.getRootContextNode().getContextNode(innerGraph);

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/respectnetwork/sdk/csp/CSP.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ public interface CSP {
* [C] Dependency Flow.
*/
public void setGuardianshipInCloud(CSPInformation cspInformation, CloudNumber guardian,
CloudNumber dependent, Date dependentBirthDate, boolean withConsent, String secretToken,
PrivateKey guardianPrivateSigningKey , String dependentToken)
CloudNumber dependent, Date dependentBirthDate, boolean withConsent, Date bornBeforeDate,
Date bornAfterDate, String secretToken, PrivateKey guardianPrivateSigningKey , String dependentToken)
throws Xdi2ClientException;


Expand All @@ -279,8 +279,8 @@ public void setGuardianshipInCloud(CSPInformation cspInformation, CloudNumber gu
* [C] Dependency Flow.
*/
public void setGuardianshipInCSP(CSPInformation cspInformation, CloudNumber guardian,
CloudNumber dependent, Date dependentBirthDate, boolean withConsent,
PrivateKey guardianPrivateSigningKey)
CloudNumber dependent, Date dependentBirthDate, boolean withConsent, Date bornBeforeDate,
Date bornAfterDate, PrivateKey guardianPrivateSigningKey)
throws Xdi2ClientException;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public class ExampleCreateGuardianship {
/* CHOOSE THE DEPENDENT'S DOB */
private static Date dependentBirthDate;

/* DEPENDENT Born before date */
private static Date bornBeforeDate;

/* DEPENDENT Born after date */
private static Date bornAfterDate;

/* CHOOSE THE INDIVIDUAL's SECRET TOKEN HERE */
private static String guardianToken = "mysecret";

Expand Down Expand Up @@ -134,10 +140,10 @@ public static void main(String[] args) throws Exception {

try {
// Set User Cloud Data
csp.setGuardianshipInCloud(cspInformation, guardianCloudNumber, dependentCloudNumber, dependentBirthDate, withConsent, guardianToken, guardianPrivateKey,dependentToken);
csp.setGuardianshipInCloud(cspInformation, guardianCloudNumber, dependentCloudNumber, dependentBirthDate, withConsent, bornBeforeDate, bornAfterDate, guardianToken, guardianPrivateKey,dependentToken);

// Set CSP Cloud Data
csp.setGuardianshipInCSP(cspInformation, guardianCloudNumber, dependentCloudNumber, dependentBirthDate, withConsent, guardianPrivateKey);
csp.setGuardianshipInCSP(cspInformation, guardianCloudNumber, dependentCloudNumber, dependentBirthDate, withConsent, bornBeforeDate, bornAfterDate, guardianPrivateKey);

// Set MemberGraph Data
csp.setGuardianshipInRN(cspInformation, guardianCloudNumber, dependentCloudNumber, dependentBirthDate, withConsent, guardianPrivateKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public void register(String cloudNameString, String dependentToken,
boolean withConsent = true;

Date dependentBirthDate = null;
Date bornBeforeDate = null;
Date bornAfterDate = null;

BasicCSPInformation cspInformation = (BasicCSPInformation) csp
.getCspInformation();
Expand Down Expand Up @@ -128,12 +130,12 @@ public void register(String cloudNameString, String dependentToken,
// Set User Cloud Data
csp.setGuardianshipInCloud(cspInformation, guardianCloudNumber,
dependentCloudNumber, dependentBirthDate, withConsent,
guardianToken, guardianPrivateKey, dependentToken);
bornBeforeDate, bornAfterDate, guardianToken, guardianPrivateKey, dependentToken);

// Set CSP Cloud Data
csp.setGuardianshipInCSP(cspInformation, guardianCloudNumber,
dependentCloudNumber, dependentBirthDate, withConsent,
guardianPrivateKey);
bornBeforeDate, bornAfterDate, guardianPrivateKey);

// Set MemberGraph Data
csp.setGuardianshipInRN(cspInformation, guardianCloudNumber,
Expand Down

0 comments on commit 8e934e9

Please sign in to comment.