/*
 * 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.statistics.impl.sql.entity;

import stroom.docref.DocRef;
import stroom.docstore.api.DocumentResourceHelper;
import stroom.event.logging.rs.api.AutoLogged;
import stroom.statistics.impl.sql.shared.StatisticResource;
import stroom.statistics.impl.sql.shared.StatisticStoreDoc;
import stroom.util.shared.EntityServiceException;

import javax.inject.Inject;

@AutoLogged
class StatisticResourceImpl implements StatisticResource {

    private final StatisticStoreStore statisticStoreStore;
    private final DocumentResourceHelper documentResourceHelper;

    @Inject
    StatisticResourceImpl(final StatisticStoreStore statisticStoreStore,
                          final DocumentResourceHelper documentResourceHelper) {
        this.statisticStoreStore = statisticStoreStore;
        this.documentResourceHelper = documentResourceHelper;
    }

    @Override
    public StatisticStoreDoc fetch(final String uuid) {
        return documentResourceHelper.read(statisticStoreStore, getDocRef(uuid));
    }

    @Override
    public StatisticStoreDoc update(final String uuid, final StatisticStoreDoc doc) {
        if (doc.getUuid() == null || !doc.getUuid().equals(uuid)) {
            throw new EntityServiceException("The document UUID must match the update UUID");
        }
        return documentResourceHelper.update(statisticStoreStore, doc);
    }

    private DocRef getDocRef(final String uuid) {
        return DocRef.builder()
                .uuid(uuid)
                .type(StatisticStoreDoc.DOCUMENT_TYPE)
                .build();
    }
}

@@ -963,16 +963,88 @@
 Inject;%0A
+import javax.inject.Provider;%0Aimport javax.inject.Singleton;%0A%0A@Singleton
 %0A@AutoLo
@@ -1122,24 +1122,33 @@
 ivate final 
+Provider%3C
 StatisticSto
@@ -1146,32 +1146,33 @@
 tisticStoreStore
+%3E
  statisticStoreS
@@ -1171,24 +1171,32 @@
 icStoreStore
+Provider
 ;%0A    privat
@@ -1199,24 +1199,33 @@
 ivate final 
+Provider%3C
 DocumentReso
@@ -1226,32 +1226,33 @@
 ntResourceHelper
+%3E
  documentResourc
@@ -1258,16 +1258,24 @@
 ceHelper
+Provider
 ;%0A%0A    @
@@ -1309,24 +1309,33 @@
 eImpl(final 
+Provider%3C
 StatisticSto
@@ -1341,16 +1341,17 @@
 oreStore
+%3E
  statist
@@ -1362,16 +1362,24 @@
 oreStore
+Provider
 ,%0A      
@@ -1404,16 +1404,25 @@
   final 
+Provider%3C
 Document
@@ -1435,16 +1435,17 @@
 ceHelper
+%3E
  documen
@@ -1459,16 +1459,24 @@
 ceHelper
+Provider
 ) %7B%0A    
@@ -1503,16 +1503,24 @@
 oreStore
+Provider
  = stati
@@ -1533,16 +1533,24 @@
 oreStore
+Provider
 ;%0A      
@@ -1578,16 +1578,24 @@
 ceHelper
+Provider
  = docum
@@ -1611,16 +1611,24 @@
 ceHelper
+Provider
 ;%0A    %7D%0A
@@ -1735,16 +1735,30 @@
 ceHelper
+Provider.get()
 .read(st
@@ -1774,16 +1774,30 @@
 oreStore
+Provider.get()
 , getDoc
@@ -2124,16 +2124,30 @@
 ceHelper
+Provider.get()
 .update(
@@ -2165,16 +2165,30 @@
 oreStore
+Provider.get()
 , doc);%0A

Apply REST stds to StatisticResourceImpl