close

Filter

loading table of contents...

Studio Developer Manual / Version 2107

Table Of Contents

7.21.2 Data Migration

To convert an existing LinkList property (Doctype property: LinkListProperty) to a new Annotated LinkList property (Doctype property: XmlProperty), functionality for migration is provided and can to be adapted to migrate custom properties.

The migration is performed on demand, that is, when the Annotated LinkList is edited. This migration approach does not migrate data as a preparation step, but is performed ongoing during write requests in normal operation mode.

Data migration from a legacy linkList property linkList to a struct linkList property structList is performed as follows:

  • The new XMLProperty needs to be added in the doctype definition. Then the doctype definition contains the legacy and the new property.
    <LinkListProperty Name="linkList" Max="1" LinkType="CMLinkable"/>
    <XmlProperty Name="structList" Grammar="coremedia-struct-2008" extensions:translatable="true"/>
    
  • Configure a Spring bean for CoreMedia Studio of type LegacyToAnnotatedLinkListAdapter with appropriate properties.
    @Bean
    LegacyToAnnotatedLinkListAdapter customAnnotatedLinkListAdapter(ContentRepository contentRepository, CapConnection connection) {
        ContentType cmTeaser = contentRepository.getContentType("CMTeaser");
    
        LegacyToAnnotatedLinkListAdapter customAdapter = new LegacyToAnnotatedLinkListAdapter();
        customAdapter.setType(cmTeaser);
        customAdapter.setProperty("structList");
        customAdapter.setLegacyProperty("linkList");
        customAdapter.setPriority(0);
        customAdapter.setInterceptingSubtypes(true);
        customAdapter.setConnection(connection);
        return customAdapter;
    }
    
  • If custom properties need to be adapted, extend the LegacyToAnnotatedLinkListAdapter and configure this bean instead.
    public class CustomAnnotatedLinkListAdapter extends LegacyToAnnotatedLinkListAdapter {
    
        @Override
        protected void populateTargetStruct(Content target, int index, StructBuilder builder, CapObject capObject) {
            super.populateTargetStruct(target, index, builder, capObject);
            //custom code
        }
    
        @Override
        protected void cleanupLegacyData(ContentWriteRequest request) {
            super.cleanupLegacyData(request);
            //custom code
        }
    }
    
            
  • Override LegacyToAnnotatedLinkListAdapter#populateTargetStruct to apply custom data to the struct list. For example, retrieve a setting from localSettings and apply it to the struct:
    @Override
    protected void populateTargetStruct(Content target, int index, StructBuilder builder, CapObject capObject) {
        super.populateTargetStruct(target, index, builder, capObject);
        Struct localSettings = capObject.getStruct("localSettings");
        if (!isEmpty(localSettings)) {
            Boolean setting = getBoolean_(localSettings, CUSTOM_SETTING);
            builder.declareBoolean(ANNOTATED_LINK_STRUCT_CUSTOM_PROPERTY_NAME, setting)
        }
    }
    
  • If required, legacy data can be cleaned up by overriding LegacyToAnnotatedLinkListAdapter#cleanupLegacyData. For example, remove a setting from localSettings, that is stored in the struct now:
    @Override
    protected void cleanupLegacyData(ContentWriteRequest request) {
        super.cleanupLegacyData(request);
        Content entity = request.getEntity();
        Map<String, Object> properties = request.getProperties();
        Struct localSettings = entity.getStruct("localSettings");
        if (localSettings != null && localSettings.get(CUSTOM_SETTING) != null) {
             StructBuilder structBuilder = localSettings.builder();
             structBuilder.remove(CUSTOM_SETTING);
             properties.put("localSettings", structBuilder.build());
        }
    }
    
  • Then, automatic migration of the legacy property linkList will be done automatically on demand, that is on write access. As soon as structList is written (via the Studio Server), the former linkList and configurable properties are stored in the new struct property structList.
  • As long as the structList property has not been written yet, read access on structList (via the Studio Server) will return the linkList as a Struct linkList.
  • After migration, read access on structList will return the struct linkList directly.
  • If the legacy linkList property is a weak link, then the structList property will lose this feature.

  • Note: The legacy property linkList is still supported but it cannot be used alongside the new property structList.
  • Note: The linklist property and the struct linklist property are different properties, the source linklist property cannot be reused with this mechanism.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.