/*
 * Copyright 2017 Crown Copyright
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package stroom.dashboard.impl.datasource;

import stroom.datasource.api.v2.AbstractField;
import stroom.datasource.shared.DataSourceResource;
import stroom.docref.DocRef;
import stroom.meta.shared.MetaFields;
import stroom.security.api.SecurityContext;

import java.util.List;
import javax.inject.Inject;

class DataSourceResourceImpl implements DataSourceResource {

    private final DataSourceProviderRegistry dataSourceProviderRegistry;
    private final SecurityContext securityContext;

    @Inject
    DataSourceResourceImpl(final DataSourceProviderRegistry dataSourceProviderRegistry,
                           final SecurityContext securityContext) {
        this.dataSourceProviderRegistry = dataSourceProviderRegistry;
        this.securityContext = securityContext;
    }

    @Override
    public List<AbstractField> fetchFields(final DocRef dataSourceRef) {
        return securityContext.secureResult(() -> {
            if (dataSourceRef.equals(MetaFields.STREAM_STORE_DOC_REF)) {
                return MetaFields.getFields();
            }

            // Elevate the users permissions for the duration of this task so they can read the index if
            // they have 'use' permission.
            return securityContext.useAsReadResult(
                    () -> dataSourceProviderRegistry.getDataSourceProvider(dataSourceRef)
                            .map(provider -> provider.getDataSource(dataSourceRef).getFields())
                            .orElse(null));
        });
    }
}

@@ -764,16 +764,63 @@
 DocRef;%0A
+import stroom.event.logging.rs.api.AutoLogged;%0A
 import s
@@ -945,16 +945,58 @@
 Inject;%0A
+import javax.inject.Provider;%0A%0A@AutoLogged
 %0Aclass D
@@ -1064,24 +1064,33 @@
 ivate final 
+Provider%3C
 DataSourcePr
@@ -1095,32 +1095,33 @@
 ProviderRegistry
+%3E
  dataSourceProvi
@@ -1127,24 +1127,32 @@
 iderRegistry
+Provider
 ;%0A    privat
@@ -1155,24 +1155,33 @@
 ivate final 
+Provider%3C
 SecurityCont
@@ -1175,32 +1175,33 @@
 %3CSecurityContext
+%3E
  securityContext
@@ -1200,16 +1200,24 @@
 yContext
+Provider
 ;%0A%0A    @
@@ -1256,16 +1256,25 @@
 l(final 
+Provider%3C
 DataSour
@@ -1291,16 +1291,17 @@
 Registry
+%3E
  dataSou
@@ -1319,16 +1319,24 @@
 Registry
+Provider
 ,%0A      
@@ -1362,16 +1362,25 @@
   final 
+Provider%3C
 Security
@@ -1386,16 +1386,17 @@
 yContext
+%3E
  securit
@@ -1403,16 +1403,24 @@
 yContext
+Provider
 ) %7B%0A    
@@ -1454,16 +1454,24 @@
 Registry
+Provider
  = dataS
@@ -1491,16 +1491,24 @@
 Registry
+Provider
 ;%0A      
@@ -1529,16 +1529,24 @@
 yContext
+Provider
  = secur
@@ -1555,16 +1555,24 @@
 yContext
+Provider
 ;%0A    %7D%0A
@@ -1689,16 +1689,30 @@
 yContext
+Provider.get()
 .secureR
@@ -2042,16 +2042,30 @@
 yContext
+Provider.get()
 .useAsRe
@@ -2126,16 +2126,30 @@
 Registry
+Provider.get()
 .getData

Apply Stroom REST resource standards to DataSourceResourceImpl