class ViewInstanceResourceProvider extends AbstractAuthorizedResourceProvider {

  protected Resource toResource(ViewInstanceEntity viewInstanceEntity, Set<String> requestedIds) {
    Resource   resource   = new ResourceImpl(Resource.Type.ViewInstance);
    ViewEntity viewEntity = viewInstanceEntity.getViewEntity();

    String viewName = viewEntity.getCommonName();
    String version  = viewEntity.getVersion();
    String name     = viewInstanceEntity.getName();

    setResourceProperty(resource, VIEW_NAME, viewName, requestedIds);
    setResourceProperty(resource, VERSION, version, requestedIds);
    setResourceProperty(resource, INSTANCE_NAME, name, requestedIds);
    setResourceProperty(resource, LABEL, viewInstanceEntity.getLabel(), requestedIds);
    setResourceProperty(resource, DESCRIPTION, viewInstanceEntity.getDescription(), requestedIds);
    setResourceProperty(resource, VISIBLE, viewInstanceEntity.isVisible(), requestedIds);
    setResourceProperty(resource, STATIC, viewInstanceEntity.isXmlDriven(), requestedIds);
    setResourceProperty(resource, CLUSTER_HANDLE, viewInstanceEntity.getClusterHandle(), requestedIds);
    setResourceProperty(resource, CLUSTER_TYPE, viewInstanceEntity.getClusterType(), requestedIds);
    ViewURLEntity viewUrl = viewInstanceEntity.getViewUrl();
    if(viewUrl != null) {
      setResourceProperty(resource, SHORT_URL, viewUrl.getUrlSuffix(), requestedIds);
      setResourceProperty(resource, SHORT_URL_NAME, viewUrl.getUrlName(), requestedIds);
    }

    // only allow an admin to access the view properties
    if (ViewRegistry.getInstance().checkAdmin()) {
      setResourceProperty(resource, PROPERTIES,
          viewInstanceEntity.getPropertyMap(), requestedIds);
    }

    Map<String, String> applicationData = new HashMap<>();

    String currentUserName = viewInstanceEntity.getCurrentUserName();
    for (ViewInstanceDataEntity viewInstanceDataEntity : viewInstanceEntity.getData()) {
      if (currentUserName.equals(viewInstanceDataEntity.getUser())) {
        applicationData.put(viewInstanceDataEntity.getName(), viewInstanceDataEntity.getValue());
      }
    }
    setResourceProperty(resource, INSTANCE_DATA,
        applicationData, requestedIds);

    String contextPath = ViewInstanceEntity.getContextPath(viewName, version, name);

    setResourceProperty(resource, CONTEXT_PATH,contextPath, requestedIds);
    setResourceProperty(resource, ICON_PATH, getIconPath(contextPath, viewInstanceEntity.getIcon()), requestedIds);
    setResourceProperty(resource, ICON64_PATH, getIconPath(contextPath, viewInstanceEntity.getIcon64()), requestedIds);

    // if the view provides its own validator then run it
    if (viewEntity.hasValidator()) {

      if (isPropertyRequested(VALIDATION_RESULT, requestedIds) ||
          isPropertyRequested(PROPERTY_VALIDATION_RESULTS, requestedIds)) {

        InstanceValidationResultImpl result =
            viewInstanceEntity.getValidationResult(viewEntity, Validator.ValidationContext.EXISTING);

        setResourceProperty(resource, VALIDATION_RESULT, ValidationResultImpl.create(result), requestedIds);
        setResourceProperty(resource, PROPERTY_VALIDATION_RESULTS, result.getPropertyResults(), requestedIds);
      }
    }

    return resource;
  }

  @Inject public  ViewInstanceResourceProvider();

}