class CloudResourceToResourceConverter extends AbstractConversionServiceAwareConverter<CloudResource, Resource> {

    @Override
    public Resource convert(CloudResource source) {
        Resource domainResource = new Resource();
        domainResource.setResourceType(source.getType());
        domainResource.setResourceName(source.getName());
        domainResource.setResourceReference(source.getReference());
        domainResource.setResourceStatus(source.getStatus());
        domainResource.setInstanceGroup(source.getGroup());
        domainResource.setInstanceId(source.getInstanceId());
        Optional.ofNullable(source.getParameters().get(CloudResource.ATTRIBUTES)).ifPresent(attributes -> {
            try {
                Json attributesJson = new Json(attributes);
                domainResource.setAttributes(attributesJson);
            } catch (IllegalArgumentException e) {
                LOGGER.info("Failed to parse resource attributes. Attributes: [{}]", source.getStringParameter(CloudResource.ATTRIBUTES), e);
                throw new IllegalStateException("Cannot parse stored resource attributes");
            }
        });
        return domainResource;
    }

}