Skip to content

Commit

Permalink
Generalize Attribute Coercion and enable to apply multiple matching …
Browse files Browse the repository at this point in the history
…Attribute Coercions in configurable order #2967
  • Loading branch information
gunterze committed Nov 26, 2021
1 parent 83cb453 commit 8ba93b3
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Apache Directory Studio on November 2, 2021, 3:52:34 PM
# Generated by Apache Directory Studio on November 26, 2021, 2:15:23 PM

# SCHEMA "DCM4CHEE-ARCHIVE"
dn: cn=dcm4chee-archive, ou=schema
Expand Down Expand Up @@ -5666,6 +5666,22 @@ m-equality: booleanMatch
m-syntax: 1.3.6.1.4.1.1466.115.121.1.7
m-singleValue: TRUE

dn: m-oid=1.2.40.0.13.1.15.110.3.428, ou=attributetypes, cn=dcm4chee-archive, ou
=schema
objectclass: metaAttributeType
objectclass: metaTop
objectclass: top
m-oid: 1.2.40.0.13.1.15.110.3.428
m-name: dcmCoercionOnFailure
m-description: Specifies behavior on failure applying this Attribute Coercion. E
numerated values: RETHROW (= propagate failure to operation applying this Attri
bute Coercion), CONTINUE (= continue to apply other matching Attribute Coercion
s of lesser priority), SUFFICIENT (= do not apply other matching Attribute Coer
cions of lesser priority). RETHROW if absent.
m-equality: caseExactIA5Match
m-syntax: 1.3.6.1.4.1.1466.115.121.1.26
m-singleValue: TRUE

dn: ou=comparators, cn=dcm4chee-archive, ou=schema
objectclass: organizationalUnit
objectclass: top
Expand Down Expand Up @@ -6741,6 +6757,7 @@ m-may: dicomDeviceName
m-may: dcmMergeAttribute
m-may: dcmCoercionParam
m-may: dcmCoercionSufficient
m-may: dcmCoercionOnFailure

dn: m-oid=1.2.40.0.13.1.15.110.4.5, ou=objectclasses, cn=dcm4chee-archive, ou=sc
hema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,11 @@ attributeTypes: ( 1.2.40.0.13.1.15.110.3.427 NAME 'dcmCoercionSufficient'
EQUALITY booleanMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.7
SINGLE-VALUE )
attributeTypes: ( 1.2.40.0.13.1.15.110.3.428 NAME 'dcmCoercionOnFailure'
DESC 'Specifies behavior on failure applying this Attribute Coercion. Enumerated values: RETHROW (= propagate failure to operation applying this Attribute Coercion), CONTINUE (= continue to apply other matching Attribute Coercions of lesser priority), SUFFICIENT (= do not apply other matching Attribute Coercions of lesser priority). RETHROW if absent.'
EQUALITY caseExactIA5Match
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
SINGLE-VALUE )
objectClasses: ( 1.2.40.0.13.1.15.110.4.4 NAME 'dcmArchiveDevice'
DESC 'DICOM Archive Device related information'
SUP top AUXILIARY
Expand Down Expand Up @@ -3052,4 +3057,5 @@ objectClasses: ( 1.2.40.0.13.1.15.110.4.45 NAME 'dcmArchiveAttributeCoercion2'
dicomDeviceName $
dcmMergeAttribute $
dcmCoercionParam $
dcmCoercionSufficient ) )
dcmCoercionSufficient $
dcmCoercionOnFailure ) )
Original file line number Diff line number Diff line change
Expand Up @@ -2501,6 +2501,12 @@ attributetype ( 1.2.40.0.13.1.15.110.3.427 NAME 'dcmCoercionSufficient'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.7
SINGLE-VALUE )

attributetype ( 1.2.40.0.13.1.15.110.3.428 NAME 'dcmCoercionOnFailure'
DESC 'Specifies behavior on failure applying this Attribute Coercion. Enumerated values: RETHROW (= propagate failure to operation applying this Attribute Coercion), CONTINUE (= continue to apply other matching Attribute Coercions of lesser priority), SUFFICIENT (= do not apply other matching Attribute Coercions of lesser priority). RETHROW if absent.'
EQUALITY caseExactIA5Match
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
SINGLE-VALUE )

objectclass ( 1.2.40.0.13.1.15.110.4.4 NAME 'dcmArchiveDevice'
DESC 'DICOM Archive Device related information'
SUP top AUXILIARY
Expand Down Expand Up @@ -3505,4 +3511,5 @@ objectclass ( 1.2.40.0.13.1.15.110.4.45 NAME 'dcmArchiveAttributeCoercion2'
dicomDeviceName $
dcmMergeAttribute $
dcmCoercionParam $
dcmCoercionSufficient ) )
dcmCoercionSufficient $
dcmCoercionOnFailure ) )
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,11 @@ olcAttributeTypes: ( 1.2.40.0.13.1.15.110.3.427 NAME 'dcmCoercionSufficient'
EQUALITY booleanMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.7
SINGLE-VALUE )
olcAttributeTypes: ( 1.2.40.0.13.1.15.110.3.428 NAME 'dcmCoercionOnFailure'
DESC 'Specifies behavior on failure applying this Attribute Coercion. Enumerated values: RETHROW (= propagate failure to operation applying this Attribute Coercion), CONTINUE (= continue to apply other matching Attribute Coercions of lesser priority), SUFFICIENT (= do not apply other matching Attribute Coercions of lesser priority). RETHROW if absent.'
EQUALITY caseExactIA5Match
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
SINGLE-VALUE )
-
replace: olcObjectClasses
olcObjectClasses: ( 1.2.40.0.13.1.15.110.4.4 NAME 'dcmArchiveDevice'
Expand Down Expand Up @@ -3054,4 +3059,5 @@ olcObjectClasses: ( 1.2.40.0.13.1.15.110.4.45 NAME 'dcmArchiveAttributeCoercion2
dicomDeviceName $
dcmMergeAttribute $
dcmCoercionParam $
dcmCoercionSufficient ) )
dcmCoercionSufficient $
dcmCoercionOnFailure ) )
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,11 @@ olcAttributeTypes: ( 1.2.40.0.13.1.15.110.3.427 NAME 'dcmCoercionSufficient'
EQUALITY booleanMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.7
SINGLE-VALUE )
olcAttributeTypes: ( 1.2.40.0.13.1.15.110.3.428 NAME 'dcmCoercionOnFailure'
DESC 'Specifies behavior on failure applying this Attribute Coercion. Enumerated values: RETHROW (= propagate failure to operation applying this Attribute Coercion), CONTINUE (= continue to apply other matching Attribute Coercions of lesser priority), SUFFICIENT (= do not apply other matching Attribute Coercions of lesser priority). RETHROW if absent.'
EQUALITY caseExactIA5Match
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
SINGLE-VALUE )
olcObjectClasses: ( 1.2.40.0.13.1.15.110.4.4 NAME 'dcmArchiveDevice'
DESC 'DICOM Archive Device related information'
SUP top AUXILIARY
Expand Down Expand Up @@ -3051,4 +3056,5 @@ olcObjectClasses: ( 1.2.40.0.13.1.15.110.4.45 NAME 'dcmArchiveAttributeCoercion2
dicomDeviceName $
dcmMergeAttribute $
dcmCoercionParam $
dcmCoercionSufficient ) )
dcmCoercionSufficient $
dcmCoercionOnFailure ) )
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ private void writeArchiveAttributeCoercion2(
writer.writeNotEmpty("dcmMergeAttribute", aac.getMergeAttributes());
writer.writeNotEmpty("dcmCoercionParam", aac.getCoercionParams());
writer.writeNotDef("dcmCoercionSufficient", aac.isCoercionSufficient(), false);
writer.writeNotNullOrDef("dcmCoercionSufficient",
aac.getCoercionOnFailure(), ArchiveAttributeCoercion2.OnFailure.RETHROW);
writer.writeEnd();
}
writer.writeEnd();
Expand Down Expand Up @@ -2932,6 +2934,9 @@ private void loadArchiveAttributeCoercion2(Collection<ArchiveAttributeCoercion2>
case "dcmCoercionSufficient":
aac.setCoercionSufficient(reader.booleanValue());
break;
case "dcmCoercionOnFailure":
aac.setCoercionOnFailure(ArchiveAttributeCoercion2.OnFailure.valueOf(reader.stringValue()));
break;
default:
reader.skipUnknownProperty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5703,6 +5703,8 @@ private Attributes storeTo(ConfigurationChanges.ModifiedObject ldapObj, ArchiveA
LdapUtils.storeNotEmpty(ldapObj, attrs, "dcmMergeAttribute", coercion.getMergeAttributes());
LdapUtils.storeNotEmpty(ldapObj, attrs, "dcmCoercionParam", coercion.getCoercionParams());
LdapUtils.storeNotDef(ldapObj, attrs, "dcmCoercionSufficient", coercion.isCoercionSufficient(), false);
LdapUtils.storeNotNullOrDef(ldapObj, attrs, "dcmCoercionOnFailure",
coercion.getCoercionOnFailure(), ArchiveAttributeCoercion2.OnFailure.RETHROW);
return attrs;
}

Expand Down Expand Up @@ -5785,6 +5787,8 @@ private void loadAttributeCoercions2(Collection<ArchiveAttributeCoercion2> coerc
coercion.setMergeAttributes(LdapUtils.stringArray(attrs.get("dcmMergeAttribute")));
coercion.setCoercionParams(LdapUtils.stringArray(attrs.get("dcmCoercionParam")));
coercion.setCoercionSufficient(LdapUtils.booleanValue(attrs.get("dcmCoercionSufficient"), false));
coercion.setCoercionOnFailure(LdapUtils.enumValue(ArchiveAttributeCoercion2.OnFailure.class,
attrs.get("dcmCoercionOnFailure"), ArchiveAttributeCoercion2.OnFailure.RETHROW));
coercions.add(coercion);
}
} finally {
Expand Down Expand Up @@ -5890,6 +5894,10 @@ private List<ModificationItem> storeDiffs(
prev.getCoercionParams(), coercion.getCoercionParams());
LdapUtils.storeDiff(ldapObj, mods, "dcmCoercionSufficient",
prev.isCoercionSufficient(), coercion.isCoercionSufficient(), false);
LdapUtils.storeDiffObject(ldapObj, mods, "dcmCoercionOnFailure",
prev.getCoercionOnFailure(),
coercion.getCoercionOnFailure(),
ArchiveAttributeCoercion2.OnFailure.RETHROW);
return mods;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
* @since Sep 2021
*/
public class ArchiveAttributeCoercion2 {
public enum OnFailure { RETHROW, CONTINUE, SUFFICENT }
public static final String NULLIFY_PIXEL_DATA = "nullify-pixel-data";
public static final String RETRIEVE_AS_RECEIVED = "retrieve-as-received";
private String commonName;
Expand All @@ -65,6 +66,7 @@ public class ArchiveAttributeCoercion2 {
private String[] sopClasses = {};
private Conditions conditions = new Conditions();
private boolean sufficient;
private OnFailure onFailure = OnFailure.RETHROW;
private Attributes.UpdatePolicy attributeUpdatePolicy = Attributes.UpdatePolicy.MERGE;
private MergeAttribute[] mergeAttributes = {};
private Device otherDevice;
Expand Down Expand Up @@ -223,6 +225,14 @@ public ArchiveAttributeCoercion2 setCoercionSufficient(boolean sufficient) {
return this;
}

public OnFailure getCoercionOnFailure() {
return onFailure;
}

public void setCoercionOnFailure(OnFailure onFailure) {
this.onFailure = onFailure;
}

public void setCoercionParam(String name, String value) {
params.put(name, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,13 +745,24 @@ public void coerce(Attributes attrs, Attributes modified) throws Exception {
}
}
for (ArchiveAttributeCoercion2 coercion : coercions) {
if (coercionFactory.getCoercionProcessor(coercion).coerce(coercion,
ctx.getLocalHostName(),
ctx.getLocalAETitle(),
ctx.getDestinationHostName(),
ctx.getDestinationAETitle(),
attrs, modified)
&& coercion.isCoercionSufficient()) break;
try {
if (coercionFactory.getCoercionProcessor(coercion).coerce(coercion,
ctx.getLocalHostName(),
ctx.getLocalAETitle(),
ctx.getDestinationHostName(),
ctx.getDestinationAETitle(),
attrs, modified)
&& coercion.isCoercionSufficient()) break;
} catch (Exception e) {
LOG.info("Failed to apply {}:\n", coercion, e);
switch(coercion.getCoercionOnFailure()){
case RETHROW:
throw e;
case CONTINUE:
continue;
}
break;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,15 +553,26 @@ private void coerceAttributes(StoreContext ctx) throws Exception {
if (rule != null) coerceLegacy(ctx, session, rule);
} else {
for (ArchiveAttributeCoercion2 coercion : coercions) {
if (coercionFactory.getCoercionProcessor(coercion).coerce(
coercion,
session.getRemoteHostName(),
session.getCallingAET(),
session.getLocalHostName(),
session.getCalledAET(),
ctx.getAttributes(),
ctx.getCoercedAttributes())
&& coercion.isCoercionSufficient()) break;
try {
if (coercionFactory.getCoercionProcessor(coercion).coerce(
coercion,
session.getRemoteHostName(),
session.getCallingAET(),
session.getLocalHostName(),
session.getCalledAET(),
ctx.getAttributes(),
ctx.getCoercedAttributes())
&& coercion.isCoercionSufficient()) break;
} catch (Exception e) {
LOG.info("{}: Failed to apply {}:\n", session, coercion, e);
switch(coercion.getCoercionOnFailure()){
case RETHROW:
throw e;
case CONTINUE:
continue;
}
break;
}
}
}
}
Expand Down

0 comments on commit 8ba93b3

Please sign in to comment.