All Downloads are FREE. Search and download functionalities are using the official Maven repository.

qa.tools.ikeeper.client.CacheClient Maven / Gradle / Ivy

package qa.tools.ikeeper.client;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;

import qa.tools.ikeeper.IssueDetails;
import qa.tools.ikeeper.annotation.BZ;
import qa.tools.ikeeper.annotation.Jira;
import qa.tools.ikeeper.client.connector.CacheConnector;
import qa.tools.ikeeper.client.connector.IssueTrackingSystemConnector;

public class CacheClient implements ITrackerClient {

    private final CacheConnector issueConnector;

    private List clients;

    public CacheClient(ITrackerClient... clients) {
        this(CacheConnector.DEFAULT_CACHE_FILE_PATH, clients);
    }

    public CacheClient(String cacheFilePath, ITrackerClient... clients) {
        issueConnector = new CacheConnector(cacheFilePath);
        this.clients = new ArrayList();
        if (clients != null) {
            for (ITrackerClient client : clients) {
                if (!(client instanceof CacheClient)) {
                    this.clients.add(client);
                }
            }
        }
    }

    @Override
    public boolean canHandle(Annotation annotation) {
        return annotation instanceof Jira || annotation instanceof BZ;
    }

    @Override
    public List getIssues(Annotation annotation) {
        Jira jiraAnnotation = (Jira) annotation;

        String[] ids = jiraAnnotation.value();
        List detailsList = new ArrayList();
        boolean cacheChanged = false;

        for (String id : ids) {
            IssueDetails details = issueConnector.getIssue(id);
            if (details == null) {
                for (ITrackerClient client : clients) {
                    if (client.canHandle(annotation)) {
                        details = client.getIssueConnector().getIssue(id);
                        if (details != null) {
                            issueConnector.addIssueDetails(details);
                            cacheChanged = true;
                        }
                    }
                }
            }
            detailsList.add(details);
        }

        if (cacheChanged) {
            issueConnector.saveData();
        }

        return detailsList;
    }

    @Override
    public IssueTrackingSystemConnector getIssueConnector() {
        return issueConnector;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy