Class: UU::OS::REST::DTO
- Inherits:
-
Object
- Object
- UU::OS::REST::DTO
- Defined in:
- uu_os_framework-0.29.16/lib/uu/os/rest/dto.rb
Overview
Each DTO should define constructor accepting JSON, Hash
or
instance of same DTO. For purpose of serialization, methods
to_hash
and to_json
should be defined. This
ancestor provides all this functionality so they need to be overriden only
in special cases.
Descendants of this class must define getters and setters (which are
delegating to attributes
from this class). These setters and
getters are responsible for any necessary data transformations.
Direct Known Subclasses
ADK::App::AppAttributes, ADK::App::AppCreate, ADK::App::AppEntryAttributes, ADK::App::AppSetAttributes, AppLog::ApplicationLog::ApplicationLogAddRecord, AppLog::ApplicationLog::ApplicationLogAttributes, AppLog::ApplicationLog::ApplicationLogCreate, AppLog::ApplicationLog::ApplicationLogGetRecordList, AppLog::ApplicationLog::ApplicationLogRecordAttributes, AppLog::ApplicationLog::ApplicationLogSetAttributes, DigitalWorkspace::DigitalWorkspace::DigitalWorkspaceRecordAttributes, DigitalWorkspace::DigitalWorkspace::DigitalWorkspaceSetRecordAttributes, ImageCatalog::ImageCatalog::ImageCatalogAttributes, ImageCatalog::ImageCatalog::ImageCatalogCreate, ImageCatalog::ImageCatalog::ImageCatalogImageEntryAttributes, ImageCatalog::ImageCatalog::ImageCatalogImportCatalogData, ImageCatalog::ImageCatalog::ImageCatalogSetAttributes, AccessRole::AccessRoleAddRoleInterface, AccessRole::AccessRoleAttributes, AccessRole::AccessRoleCreate, AccessRole::AccessRoleGetRoleInterfaceListItem, AccessRole::AccessRoleRemoveRoleInterface, AccessRole::AccessRoleSetAttributes, Activity::ActivityAttributes, Activity::ActivityCreate, Activity::ActivitySetAttributes, Activity::ActivitySetCompetentRole, Activity::ActivitySetExecutiveRole, Activity::ActivitySetState, Activity::ActivityStateAttributes, Activity::ActivityStateTemplateAttributes, ActivityAction::ActivityActionAttributes, ActivityAction::ActivityActionCreate, ActivityCondition::ActivityConditionAttributes, ActivityCondition::ActivityConditionCreate, ActivityCondition::ActivityConditionGetAttributes, ActivityStateTemplate::ActivityStateTemplateAttributes, ActivityStateTemplate::ActivityStateTemplateCreate, ActivityStateTemplate::ActivityStateTemplateSetAttributes, ActivityTemplate::ActivityTemplateAttributes, ActivityTemplate::ActivityTemplateCreate, ActivityTemplate::ActivityTemplateSetAttributes, AllFromOrganizationalUnitCast::AllFromOrganizationalUnitCastAttributes, AllFromOrganizationalUnitCast::AllFromOrganizationalUnitCastCreate, AllFromOrganizationalUnitCast::AllFromOrganizationalUnitCastDelete, AllFromOrganizationalUnitCast::AllFromOrganizationalUnitCastExists, AllFromOrganizationalUnitCast::AllFromOrganizationalUnitCastGetAttributes, AllFromOrganizationalUnitCast::AllFromOrganizationalUnitCastSetAttributes, AppMetaModel::AppMetaModelAttributes, AppMetaModel::AppMetaModelCreate, AppMetaModel::AppMetaModelEntryAttributes, AppMetaModel::AppMetaModelInstallAppParameters, AppMetaModel::AppMetaModelInstallSharedMetaModelAppParameters, AppMetaModel::AppMetaModelSetAttributes, AppPackage::AppPackageAttributes, AppPackage::AppPackageCreate, AppPackage::AppPackageEntryAttributes, AppPackage::AppPackageExport, AppPackage::AppPackageGetExportData, AppPackage::AppPackageSetAttributes, Artifact::ArtifactAttributes, Artifact::ArtifactCreate, Artifact::ArtifactExport, Artifact::ArtifactGetExportData, Artifact::ArtifactMove, Artifact::ArtifactPresentationAttributes, Artifact::ArtifactSetAttributes, Artifact::ArtifactSetCompetentRole, Artifact::ArtifactSetPresentationAttributes, Artifact::ArtifactSetState, Artifact::ArtifactSetVisualPresentation, Artifact::ReferenceEntry, ArtifactSearch::ArtifactSearchResultItem, ArtifactStateTemplate::ArtifactStateTemplateAttributes, ArtifactStateTemplate::ArtifactStateTemplateCreate, ArtifactStateTemplate::ArtifactStateTemplateSetAttributes, Attachment::AttachmentAttributes, Attachment::AttachmentCheckIn, Attachment::AttachmentCheckOut, Attachment::AttachmentCreate, Attachment::AttachmentDeleteVersion, Attachment::AttachmentGetVersionAttributes, Attachment::AttachmentGetVersionData, Attachment::AttachmentSetAttributes, Attachment::AttachmentVersionAttributes, BasicGroup::BasicGroupAddArtifactInterface, BasicGroup::BasicGroupAttributes, BasicGroup::BasicGroupCreate, BasicGroup::BasicGroupGetArtifactInterfaceListItem, BasicGroup::BasicGroupGetBasicGroupListItem, BasicGroup::BasicGroupRemoveArtifactInterface, BasicGroup::BasicGroupSetAttributes, Cast::CastAccessRoleAttributes, Cast::CastAttributes, Cast::CastCreate, Cast::CastDelete, Cast::CastExists, Cast::CastGetAttributes, Cast::CastHistoryAttributes, Cast::CastSetAttributes, Cast::CastVerifyCastExistence, Command::CommandAttributes, Command::CommandCreate, Command::CommandExport, Command::CommandGetExportData, Command::CommandSetAttributes, Company::CompanyAttributes, Company::CompanyCreate, Company::CompanyEntryAttributes, Company::CompanySetAttributes, Env::Lock::LockCreate, Env::Process::ProcessEvent, Env::Process::ProcessMessage, Env::Process::ProcessResult, Env::Process::ProcessRun, Folder::FolderAttributes, Folder::FolderCreate, Folder::FolderEntryAttributes, Folder::FolderExport, Folder::FolderGetExportData, Folder::FolderSetAttributes, Friend::FriendAttributes, Friend::FriendCreate, Friend::FriendSetAttributes, Group::GroupAddRoleInterface, Group::GroupAttributes, Group::GroupCancelActivities, Group::GroupCreate, Group::GroupGetRoleInterfaceListItem, Group::GroupPropagateActivities, Group::GroupRemoveRoleInterface, Group::GroupSetAttributes, ImageCatalog::ImageCatalogImageEntryAttributes, Macro::MacroExec, MetaAccessRole::MetaAccessRoleAddRoleInterface, MetaAccessRole::MetaAccessRoleAttributes, MetaAccessRole::MetaAccessRoleCopy, MetaAccessRole::MetaAccessRoleCreate, MetaAccessRole::MetaAccessRoleExport, MetaAccessRole::MetaAccessRoleGetExportData, MetaAccessRole::MetaAccessRoleGetRoleInterfaceListItem, MetaAccessRole::MetaAccessRoleRemoveRoleInterface, MetaAccessRole::MetaAccessRoleSetAttributes, MetaArtifact::MetaArtifactAttributes, MetaArtifact::MetaArtifactCopy, MetaArtifact::MetaArtifactCreate, MetaArtifact::MetaArtifactDefaultPresentationAttributes, MetaArtifact::MetaArtifactExport, MetaArtifact::MetaArtifactGetExportData, MetaArtifact::MetaArtifactPresentationAttributes, MetaArtifact::MetaArtifactSetAttributes, MetaArtifact::MetaArtifactSetDefaultPresentationAttributes, MetaArtifact::MetaArtifactSetPresentationAttributes, MetaGroup::MetaGroupAddRoleInterface, MetaGroup::MetaGroupAttributes, MetaGroup::MetaGroupCopy, MetaGroup::MetaGroupCreate, MetaGroup::MetaGroupExport, MetaGroup::MetaGroupGetExportData, MetaGroup::MetaGroupGetRoleInterfaceListItem, MetaGroup::MetaGroupRemoveRoleInterface, MetaGroup::MetaGroupSetAttributes, MetaModel::ArtifactInterfaceAddUseCase, MetaModel::ArtifactInterfaceAttributes, MetaModel::ArtifactInterfaceCreate, MetaModel::ArtifactInterfaceRemoveUseCase, MetaModel::ArtifactInterfaceSetAttributes, MetaModel::ArtifactInterfaceUseCaseAttributes, MetaModel::MetaModelAttributes, MetaModel::MetaModelCreate, MetaModel::MetaModelEntryAttributes, MetaModel::MetaModelSetAttributes, MetaPermission::MetaPermissionCreateMask, MetaPermission::MetaPermissionGetAuthorityData, MetaPermission::MetaPermissionGetAuthorityListItem, MetaPermission::MetaPermissionGetMaskAttributes, MetaPermission::MetaPermissionGetMaskData, MetaPermission::MetaPermissionGetSystemGroupAttributes, MetaPermission::MetaPermissionGrant, MetaPermission::MetaPermissionRevoke, MetaPermission::MetaPermissionSetMaskAttributes, MetaPermission::MetaPermissionSetMaskData, MetaRole::MetaRoleAddRoleInterface, MetaRole::MetaRoleAttributes, MetaRole::MetaRoleCopy, MetaRole::MetaRoleCreate, MetaRole::MetaRoleExport, MetaRole::MetaRoleGetExportData, MetaRole::MetaRoleGetRoleInterfaceListItem, MetaRole::MetaRoleRemoveRoleInterface, MetaRole::MetaRoleSetAttributes, MetaUseCaseRealization::MetaUseCaseRealizationAttributes, MetaUseCaseRealization::MetaUseCaseRealizationCopy, MetaUseCaseRealization::MetaUseCaseRealizationSetAttributes, MetaVisualUseCase::MetaVisualUseCaseAttributes, MetaVisualUseCase::MetaVisualUseCaseCopy, MetaVisualUseCase::MetaVisualUseCaseSetAttributes, OrganizationalUnit::OrganizationalUnitAttributes, OrganizationalUnit::OrganizationalUnitCreate, OrganizationalUnit::OrganizationalUnitEntryAttributes, OrganizationalUnit::OrganizationalUnitSetAttributes, Permission::PermissionAuthorize, Permission::PermissionAuthorizeResult, Permission::PermissionGetAuthorityData, Permission::PermissionGetAuthorityListItem, Permission::PermissionGetMaskAttributes, Permission::PermissionGetSystemGroupAttributes, Permission::PermissionGrant, Permission::PermissionRevoke, PersonalAccessRole::PersonalAccessRoleAddRoleInterface, PersonalAccessRole::PersonalAccessRoleAttributes, PersonalAccessRole::PersonalAccessRoleCreate, PersonalAccessRole::PersonalAccessRoleGetRoleInterfaceListItem, PersonalAccessRole::PersonalAccessRoleRemoveRoleInterface, PersonalAccessRole::PersonalAccessRoleSetAttributes, PersonalRole::PersonalRoleAccountAttributes, PersonalRole::PersonalRoleArtifactPresentationAttributes, PersonalRole::PersonalRoleAttributes, PersonalRole::PersonalRoleCreate, PersonalRole::PersonalRoleRelocate, PersonalRole::PersonalRoleRemoveAccount, PersonalRole::PersonalRoleSetAccessCodes, PersonalRole::PersonalRoleSetArtifactPresentationAttributes, PersonalRole::PersonalRoleSetAttributes, PersonalRole::ProfileAttributes, PersonalRole::ProfileSetAttributes, PersonalRole::TerritoryAttributes, Property::PropertyAttributes, Property::PropertyCollectionAttributes, Property::PropertyCreate, Property::PropertyCreateCollection, Property::PropertyDeleteCollection, Property::PropertyEntryAttributes, Property::PropertyMove, Property::PropertyMoveCollection, Property::PropertySetAttributes, Property::PropertySetCollectionAttributes, PropertyTemplate::PropertyTemplateAttributes, PropertyTemplate::PropertyTemplateCollectionAttributes, PropertyTemplate::PropertyTemplateCollectionCreate, PropertyTemplate::PropertyTemplateCreate, PropertyTemplate::PropertyTemplateDeleteCollection, PropertyTemplate::PropertyTemplateEntryAttributes, PropertyTemplate::PropertyTemplateMove, PropertyTemplate::PropertyTemplateMoveCollection, PropertyTemplate::PropertyTemplateSetAttributes, PropertyTemplate::PropertyTemplateSetCollectionAttributes, QoS::AccessRoleGetQoS, QoS::AccessRoleSetQoS, QoS::TerritoryGetQoS, QoS::TerritorySetQoS, BinaryValue, PagingCriteria, UU::OS::Role::RoleAddRoleInterface, UU::OS::Role::RoleAttributes, UU::OS::Role::RoleCreate, UU::OS::Role::RoleGetArtifactListItem, UU::OS::Role::RoleGetRoleInterfaceListItem, UU::OS::Role::RoleRemoveRoleInterface, UU::OS::Role::RoleSetAttributes, UU::OS::RoleInterface::RoleInterfaceAddMetaArtifact, UU::OS::RoleInterface::RoleInterfaceAttributes, UU::OS::RoleInterface::RoleInterfaceCreate, UU::OS::RoleInterface::RoleInterfaceExport, UU::OS::RoleInterface::RoleInterfaceGetExportData, UU::OS::RoleInterface::RoleInterfaceGetMetaArtifactListItem, UU::OS::RoleInterface::RoleInterfaceGetRoleListItem, UU::OS::RoleInterface::RoleInterfaceRemoveMetaArtifact, UU::OS::RoleInterface::RoleInterfaceSetAttributes, UU::OS::RoleSearch::RoleSearchResultItem, Script::ScriptExec, Sheet::SheetAttributes, Sheet::SheetCheckIn, Sheet::SheetCheckOut, Sheet::SheetCreate, Sheet::SheetDeleteComponent, Sheet::SheetDeleteVersion, Sheet::SheetDeleteVersions, Sheet::SheetGetComponentContent, Sheet::SheetGetComponentData, Sheet::SheetGetImageData, Sheet::SheetGetSheetData, Sheet::SheetGetVersionAttributes, Sheet::SheetGetVersionData, Sheet::SheetReplaceComponent, Sheet::SheetSetAttributes, Sheet::SheetVersionAttributes, SheetTemplate::SheetTemplateAttributes, SheetTemplate::SheetTemplateCheckIn, SheetTemplate::SheetTemplateCreate, SheetTemplate::SheetTemplateGetData, SheetTemplate::SheetTemplateSetAttributes, Shortcut::ShortcutAttributes, Shortcut::ShortcutCreate, Shortcut::ShortcutRelocate, Shortcut::ShortcutSetAttributes, UESURI, UUEE::UUEEAttributes, UUEE::UUEECreate, UUEE::UUEESetAccessCodes, UUEE::UUEESetAttributes, UseCase::UseCaseAttributes, UseCase::UseCaseCreate, UseCase::UseCaseGetOptions, UseCase::UseCaseSetAttributes, UseCase::UseCaseSetOptions, UseCaseLog::UseCaseLogAddRecord, UseCaseLog::UseCaseLogRecordEntry, UseCaseRealization::UseCaseRealizationAttributes, UseCaseRealization::UseCaseRealizationCreate, UseCaseRealization::UseCaseRealizationGetOptions, UseCaseRealization::UseCaseRealizationGetUseCaseListItem, UseCaseRealization::UseCaseRealizationSetAttributes, UseCaseRealization::UseCaseRealizationSetOptions, VisualUseCase::VisualUseCaseAttributes, VisualUseCase::VisualUseCaseCreate, VisualUseCase::VisualUseCaseExport, VisualUseCase::VisualUseCaseGetExportData, VisualUseCase::VisualUseCaseGetOptions, VisualUseCase::VisualUseCaseGetUseCaseListItem, VisualUseCase::VisualUseCaseSetAttributes, VisualUseCase::VisualUseCaseSetOptions, Widget::WidgetAttributes, Widget::WidgetCreate, Widget::WidgetExport, Widget::WidgetGetExportData, Widget::WidgetGetWidgetListItem, Widget::WidgetSetAttributes, UU::ObjectStore::ObjectSchema::ObjectSchemaAttributes, UU::ObjectStore::ObjectSchema::ObjectSchemaCreate, UU::ObjectStore::ObjectSchema::ObjectSchemaCreateIndex, UU::ObjectStore::ObjectSchema::ObjectSchemaDelete, UU::ObjectStore::ObjectSchema::ObjectSchemaDeleteIndex, UU::ObjectStore::ObjectSchema::ObjectSchemaGetIndexList, UU::ObjectStore::ObjectSchema::ObjectSchemaGetSchemaList, UU::ObjectStore::ObjectSchema::ObjectSchemaIndexAttributes, UU::ObjectStore::ObjectSchema::ObjectSchemaSetAttributes, UU::ObjectStore::ObjectStoreControl::ObjectStoreAttributes, UU::ObjectStore::ObjectStoreControl::ObjectStoreCreate, UU::ObjectStore::ObjectStoreControl::ObjectStoreDelete, UU::ObjectStore::ObjectStoreControl::ObjectStoreGetStoreList, UU::ObjectStore::ObjectStoreControl::ObjectStoreSetAttributes, UU::ObjectStore::ObjectStoreControl::ObjectStoreTransfer, UU::ObjectStore::ObjectStoreRepository::ObjectStoreRepositoryAttributes, UU::ObjectStore::ObjectStoreRepository::ObjectStoreRepositoryCreate, UU::ObjectStore::ObjectStoreRepository::ObjectStoreRepositoryGetRepositoryList, UU::ObjectStore::ObjectStoreRepository::ObjectStoreRepositorySetAttributes, UU::OperationalStats::OperationalStats::OperationalStatsTerritoryRecord, Request::Request::RequestAttributes, Request::Request::RequestSetAttributes, UDS::Bucket::BlobAttributes, UDS::Bucket::BucketAttributes, UDS::Bucket::BucketCreate, UDS::Bucket::BucketSetAttributes
Instance Method Summary (collapse)
-
- (DTO) initialize(init_data = nil)
constructor
Creates new instance of DTO.
-
- (Hash) to_hash
Serializes DTO to Hash.
-
- (String) to_json(options = nil)
Serialize DTO to JSON.
Constructor Details
- (DTO) initialize(init_data = nil)
Creates new instance of DTO. In case there is some problem with default
parsing of init_data
, method
handle_custom_init_data
is invoked in order to provide
descendants option to handle special types of init_data
.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/dto.rb', line 25 def initialize(init_data = nil) @attributes = {} original_data = init_data if init_data.nil? return elsif init_data.kind_of?self.class # In case of self instance only reuse existing DTO attributes @attributes = init_data.send(:attributes) return elsif init_data.kind_of?String # Input of type String should be JSON with serialized DTO begin init_data = JSON.parse(init_data, :symbolize_names => true) rescue Exception => e begin handle_custom_init_data(original_data, e) return rescue Exception => e1 if init_data.empty? # In case init_data is empty String (invalid JSON) and init_data are not # handled by particular DTO type, consider empty init_data as nil init_data # and create empty instance of this DTO. return else raise e1 end end end end if !init_data.kind_of?Hash error = ArgumentError.new("Parameter must be a valid JSON String, a Hash or an instance of #{self.class}, but was #{init_data.class}.") handle_custom_init_data(original_data, error) return end # Handle attributes given as Hash (either given directly or deserialized from JSON) init_data.entries.each do |attribute| # Delegate each attribute to setter in particular DTO setter = get_setter(attribute[0]) begin self.send(setter, attribute[1]) rescue Exception => e handle_custom_init_data(original_data, e) return end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method, *args, &block)
Handle invocation of missing setter while constructing new DTO.
106 107 108 109 110 111 112 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/dto.rb', line 106 def method_missing(method, *args, &block) if (method.to_s[/=$/]) && (args.size == 1) UU::OS::Logger.new(self).warning("#{self.class} does not contain setter \"#{method}\". Either DTO is being created with wrong parameters or there is some change in API.") else super.method_missing(method, args, &block) end end |
Instance Method Details
- (Hash) to_hash
Serializes DTO to Hash. Serialization is done recursively, that means
to_hash
is invoked on all attributes of type DTO. Manipulating
data in returned structure does not change data in original DTOs. This
method should be overridden in descendants in case some additional
attributes transformation is necessary.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/dto.rb', line 79 def to_hash result = {} @attributes.entries.each do |attribute| if attribute[1].kind_of?UU::OS::REST::DTO result[attribute[0]] = attribute[1].to_hash else result[attribute[0]] = attribute[1] end end result end |
- (String) to_json(options = nil)
Serialize DTO to JSON. DTO is first serialized to Hash using method
to_hash
, result is than serialized to JSON. This method should
be overridden in descendants in case some additional attributes
transformation is necessary.
99 100 101 |
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/dto.rb', line 99 def to_json( = nil) to_hash.to_json() end |