package com.hp.autonomy.frontend.find.idol.savedsearches.savedsnapshot;

import com.hp.autonomy.frontend.find.core.savedsearches.EmbeddableIndex;
import com.hp.autonomy.frontend.find.core.savedsearches.savedsnapshot.SavedSnapshot;
import com.hp.autonomy.frontend.find.core.savedsearches.savedsnapshot.SavedSnapshotController;
import com.hp.autonomy.frontend.find.core.savedsearches.savedsnapshot.SavedSnapshotService;
import com.hp.autonomy.hod.client.api.resource.ResourceIdentifier;
import com.hp.autonomy.hod.client.error.HodErrorException;
import com.hp.autonomy.searchcomponents.core.search.DocumentsService;
import com.hp.autonomy.searchcomponents.hod.search.HodSearchResult;
import com.hp.autonomy.searchcomponents.idol.search.IdolQueryRestrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Controller
@RequestMapping(SavedSnapshotController.PATH)
public class IdolSavedSnapshotController extends SavedSnapshotController {

    @Autowired
    public IdolSavedSnapshotController(SavedSnapshotService service, DocumentsService<ResourceIdentifier, HodSearchResult, HodErrorException> documentsService) {
        super(service, documentsService);
    }

    private List<String> getDatabases(Set<EmbeddableIndex> indexes) {
        List<String> databases = new ArrayList<>();

        for(EmbeddableIndex index: indexes) {
            databases.add(index.getName());
        }

        return databases;
    }

    @Override
    protected String getStateToken(final SavedSnapshot snapshot) throws Exception {
        IdolQueryRestrictions.Builder queryRestrictionsBuilder = new IdolQueryRestrictions.Builder()
                .setDatabases(this.getDatabases(snapshot.getIndexes()))
                .setQueryText(this.getQueryText(snapshot)).setFieldText(this.getFieldText(snapshot.getParametricValues()))
                .setMaxDate(snapshot.getMaxDate())
                .setMinDate(snapshot.getMinDate());

        return documentsService.getStateToken(queryRestrictionsBuilder.build(), Integer.MAX_VALUE);
    }
}

@@ -66,16 +66,75 @@
 pshot;%0A%0A
+import com.autonomy.aci.client.services.AciErrorException;%0A
 import c
@@ -474,134 +474,8 @@
 ce;%0A
-import com.hp.autonomy.hod.client.api.resource.ResourceIdentifier;%0Aimport com.hp.autonomy.hod.client.error.HodErrorException;%0A
 impo
@@ -584,19 +584,20 @@
 nts.
-hod
+core
 .search.
 HodS
@@ -592,19 +592,16 @@
 .search.
-Hod
 SearchRe
@@ -1062,16 +1062,57 @@
 ntroller
+%3CString, SearchResult, AciErrorException%3E
  %7B%0A%0A    
@@ -1212,31 +1212,16 @@
 ice%3C
-ResourceIdentifier, Hod
+String, 
 Sear
@@ -1234,11 +1234,11 @@
 lt, 
-Hod
+Aci
 Erro

Fix for wrong types.