-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#451: extensible set of supported controls
- Loading branch information
Showing
7 changed files
with
243 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...rc/main/java/org/openehealth/ipf/commons/ihe/hpd/controls/strategies/ControlStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* 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 org.openehealth.ipf.commons.ihe.hpd.controls.strategies; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
import javax.naming.ldap.BasicControl; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @author Dmytro Rud | ||
*/ | ||
public interface ControlStrategy { | ||
|
||
BasicControl deserializeDsml2(byte[] berBytes, boolean criticality) throws IOException; | ||
|
||
BasicControl deserializeJson(JsonNode node) throws IOException; | ||
|
||
void serializeJson(BasicControl control, JsonGenerator gen) throws IOException; | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...va/org/openehealth/ipf/commons/ihe/hpd/controls/strategies/PaginationControlStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* 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 org.openehealth.ipf.commons.ihe.hpd.controls.strategies; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
import javax.naming.ldap.BasicControl; | ||
import javax.naming.ldap.PagedResultsControl; | ||
import javax.naming.ldap.PagedResultsResponseControl; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @author Dmytro Rud | ||
*/ | ||
public class PaginationControlStrategy implements ControlStrategy { | ||
|
||
@Override | ||
public BasicControl deserializeDsml2(byte[] berBytes, boolean criticality) throws IOException { | ||
return new PagedResultsResponseControl(PagedResultsResponseControl.OID, criticality, berBytes); | ||
} | ||
|
||
@Override | ||
public BasicControl deserializeJson(JsonNode node) throws IOException { | ||
return new PagedResultsControl(node.get("size").intValue(), node.get("cookie").binaryValue(), node.get("critical").booleanValue()); | ||
} | ||
|
||
@Override | ||
public void serializeJson(BasicControl control, JsonGenerator gen) throws IOException { | ||
PagedResultsResponseControl paginationControl = (PagedResultsResponseControl) control; | ||
gen.writeNumberField("size", paginationControl.getResultSize()); | ||
if (paginationControl.getCookie() != null) { | ||
gen.writeBinaryField("cookie", paginationControl.getCookie()); | ||
} | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
...ain/java/org/openehealth/ipf/commons/ihe/hpd/controls/strategies/SortControlStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* 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 org.openehealth.ipf.commons.ihe.hpd.controls.strategies; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import org.openehealth.ipf.commons.ihe.hpd.controls.sorting.SortControl2; | ||
|
||
import javax.naming.ldap.BasicControl; | ||
import javax.naming.ldap.SortKey; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
|
||
/** | ||
* @author Dmytro Rud | ||
*/ | ||
public class SortControlStrategy implements ControlStrategy { | ||
|
||
@Override | ||
public BasicControl deserializeDsml2(byte[] berBytes, boolean criticality) throws IOException { | ||
return new SortControl2(berBytes, criticality); | ||
} | ||
|
||
@Override | ||
public BasicControl deserializeJson(JsonNode node) throws IOException { | ||
ArrayList<SortKey> keys = new ArrayList<>(); | ||
JsonNode keysNode = node.get("keys"); | ||
Iterator<JsonNode> keyNodes = keysNode.elements(); | ||
while (keyNodes.hasNext()) { | ||
JsonNode keyNode = keyNodes.next(); | ||
keys.add(new SortKey(keyNode.get("attrId").textValue(), keyNode.get("ascending").booleanValue(), keyNode.get("matchingRuleId").textValue())); | ||
} | ||
return new SortControl2(node.get("critical").asBoolean(), keys.toArray(new SortKey[0])); | ||
} | ||
|
||
@Override | ||
public void serializeJson(BasicControl control, JsonGenerator gen) throws IOException { | ||
SortControl2 sortControl = (SortControl2) control; | ||
gen.writeArrayFieldStart("keys"); | ||
for (SortKey sortKey : sortControl.getKeys()) { | ||
gen.writeStartObject(); | ||
gen.writeStringField("attrId", sortKey.getAttributeID()); | ||
gen.writeStringField("matchingRuleId", sortKey.getMatchingRuleID()); | ||
gen.writeBooleanField("ascending", sortKey.isAscending()); | ||
gen.writeEndObject(); | ||
} | ||
gen.writeEndArray(); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
.../org/openehealth/ipf/commons/ihe/hpd/controls/strategies/SortResponseControlStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* 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 org.openehealth.ipf.commons.ihe.hpd.controls.strategies; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import org.openehealth.ipf.commons.ihe.hpd.controls.sorting.SortResponseControl2; | ||
|
||
import javax.naming.ldap.BasicControl; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @author Dmytro Rud | ||
*/ | ||
public class SortResponseControlStrategy implements ControlStrategy { | ||
|
||
@Override | ||
public BasicControl deserializeDsml2(byte[] berBytes, boolean criticality) throws IOException { | ||
return new SortResponseControl2(berBytes, criticality); | ||
} | ||
|
||
@Override | ||
public BasicControl deserializeJson(JsonNode node) throws IOException { | ||
return new SortResponseControl2(node.get("resultCode").intValue(), node.get("failedAttrId").asText(), node.get("critical").booleanValue()); | ||
} | ||
|
||
@Override | ||
public void serializeJson(BasicControl control, JsonGenerator gen) throws IOException { | ||
SortResponseControl2 sortResponseControl = (SortResponseControl2) control; | ||
gen.writeNumberField("resultCode", sortResponseControl.getResultCode()); | ||
if (sortResponseControl.getFailedAttributeName() != null) { | ||
gen.writeStringField("failedAttrId", sortResponseControl.getFailedAttributeName()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters