| Back | Main view
Custom property management using IMiS/Storage Connector JAVA
Product: | IMiS/Storage Connector JAVA |
Release: | 10.2.2110 |
Date: | 10/18/2022 |
Case:
Custom property management using IMiS/Storage Connector JAVA
Description:
This example demonstrates operations which reads, updates and deletes entity's custom property on the IMiS/ARChive Server.
Below is a description of operations for the custom property management.
1. Read entity properties values
Operation reads entity properties and values.
JAVA
IArchive archive = IMIS_ARCHIVE;
String id= "<entity-identifier>";
IEntity entity = null;
try {
// Open entity in read mode
entity = mArchive.openEntity(EntityIdKind.INTERNAL, id, null, AccessMode.READ, null);
// Read properties
for (IProperty property : entity.getPropertiesList()) {
if (property.isPickList()) {
for (IPickListValue value : property.getValues(IPickListValue.class)) {
System.out.println("Property name:'" + property.getName() + "', key:'" + value.getKey() +
"', value:'" + value.getValue() + "'");
}
continue;
}
switch (property.getType()) {
case BINARY:
for (IBinaryValue value : property.getValues(IBinaryValue.class)) {
System.out.println("Property name:'" + property.getName() + "', contentType:'" + value.getContentType() +
"', extension:'" + value.getExtension() + "', value:'" + new String(value.getValue()) + "'");
}
break;
case BOOL:
for (Boolean value : property.getValues(Boolean.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case DATE:
case DATE_TIME:
case TIME:
for (Calendar value : property.getValues(Calendar.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case DECIMAL1:
case DECIMAL2:
case DECIMAL3:
case DECIMAL4:
case DECIMAL5:
case DECIMAL6:
case DECIMAL7:
case DECIMAL8:
case DECIMAL9:
case DECIMAL10:
for (BigDecimal value : property.getValues(BigDecimal.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case DIRECTORY_ENTITY:
for (IDirectoryEntity value : property.getValues(IDirectoryEntity.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value.getSubject() + "'");
}
break;
case DOUBLE:
for (Double value : property.getValues(Double.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case INT8:
for (Byte value : property.getValues(Byte.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case INT16:
case UINT8:
for (Short value : property.getValues(Short.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case INT32:
case UINT16:
for (Integer value : property.getValues(Integer.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case INT64:
case UINT32:
for (Long value : property.getValues(Long.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case INT128:
case UINT64:
case UINT128:
for (BigInteger value : property.getValues(BigInteger.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case ENTITY_REFERENCE:
case STRING10:
case STRING20:
case STRING30:
case STRING40:
case STRING50:
case STRING100:
case STRING200:
for (String value : property.getValues(String.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case STRINGMAX:
for (IStringMaxValue value : property.getValues(IStringMaxValue.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value.getValue() + "'");
}
break;
default:
break;
}
}
}
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
finally {
// Close entity
if (null != entity) {
try {
entity.close();
}
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}
2. Read entity property values
Operation reads entity property values with specified property name.
JAVA
IArchive archive = IMIS_ARCHIVE;
String id= "<entity-identifier>";
String propertyName = "<property-name>";
IEntity entity = null;
try {
// Open entity in read mode
entity = mArchive.openEntity(EntityIdKind.INTERNAL, id, null, AccessMode.READ, null);
// Read properties
IProperty property = entity.getProperties().get(propertyName);
if (null == property) {
System.out.println("Property name:'" + propertyName + "' does not exist on entity");
return;
}
if (property.isPickList()) {
for (IPickListValue value : property.getValues(IPickListValue.class)) {
System.out.println("Property name:'" + property.getName() + "', key:'" + value.getKey() +
"', value:'" + value.getValue() + "'");
}
}
else {
switch (property.getType()) {
case BINARY:
for (IBinaryValue value : property.getValues(IBinaryValue.class)) {
System.out.println(
"Property name:'" + property.getName() + "', contentType:'" + value.getContentType() + "', extension:'" + value.getExtension() + "', value:'" + new String(
value.getValue()) + "'");
}
break;
case BOOL:
for (Boolean value : property.getValues(Boolean.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case DATE:
case DATE_TIME:
case TIME:
for (Calendar value : property.getValues(Calendar.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case DECIMAL1:
case DECIMAL2:
case DECIMAL3:
case DECIMAL4:
case DECIMAL5:
case DECIMAL6:
case DECIMAL7:
case DECIMAL8:
case DECIMAL9:
case DECIMAL10:
for (BigDecimal value : property.getValues(BigDecimal.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case DIRECTORY_ENTITY:
for (IDirectoryEntity value : property.getValues(IDirectoryEntity.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value.getSubject() + "'");
}
break;
case DOUBLE:
for (Double value : property.getValues(Double.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case INT8:
for (Byte value : property.getValues(Byte.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case INT16:
case UINT8:
for (Short value : property.getValues(Short.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case INT32:
case UINT16:
for (Integer value : property.getValues(Integer.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case INT64:
case UINT32:
for (Long value : property.getValues(Long.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case INT128:
case UINT64:
case UINT128:
for (BigInteger value : property.getValues(BigInteger.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case ENTITY_REFERENCE:
case STRING10:
case STRING20:
case STRING30:
case STRING40:
case STRING50:
case STRING100:
case STRING200:
for (String value : property.getValues(String.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value + "'");
}
break;
case STRINGMAX:
for (IStringMaxValue value : property.getValues(IStringMaxValue.class)) {
System.out.println("Property name:'" + property.getName() + "', value:'" + value.getValue() + "'");
}
break;
default:
break;
}
}
}
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
finally {
// Close entity
if (null != entity) {
try {
entity.close();
}
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}
3. Update entity property value
Operation updates entity property with specified property name and type STRING10.
JAVA
IArchive archive = IMIS_ARCHIVE;
String id= "<entity-identifier>";
String propertyName = "<property-name>";
String value = "<property-value>";
IEntity entity = null;
try {
// Open entity in read-write mode
entity = mArchive.openEntity(EntityIdKind.INTERNAL, id, null, AccessMode.READ_WRITE, null);
// Read properties
IProperty property = entity.getProperties().get(propertyName);
if (null == property) {
System.out.println("Property name:'" + propertyName + "' does not exist on entity");
return;
}
if (!property.isPickList() && PropertyType.STRING10 == property.getType()) {
List<String> values = new ArrayList<String>();
values.add(value);
property.setValues(String.class, values);
}
else {
System.out.println("Property name:'" + propertyName + "' is not type STRING10");
return;
}
// Save entity
entity.save();
}
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
finally {
// Close entity
if (null != entity) {
try {
entity.close();
}
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}
4. Delete entity property values
Operation deletes entity property values with specified property name.
JAVA
IArchive archive = IMIS_ARCHIVE;
String id= "<entity-identifier>";
String propertyName = "<property-name>";
IEntity entity = null;
try {
// Open entity in read-write mode
entity = mArchive.openEntity(EntityIdKind.INTERNAL, id, null, AccessMode.READ_WRITE, null);
// Read properties
IProperty property = entity.getProperties().get(propertyName);
if (null == property) {
System.out.println("Property name:'" + propertyName + "' does not exist on entity");
return;
}
// Clear property values
property.clear();
// Save entity
entity.save();
}
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
finally {
// Close entity
if (null != entity) {
try {
entity.close();
}
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}
Related Documents:
| Back | Main view