GenesysImageManagerApiService.java

/*
 * Copyright 2025 Global Crop Diversity Trust
 *
 * 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 org.gringlobal.api.v2.facade;

import org.gringlobal.api.model.integration.GenesysAttachmentDTO;
import org.gringlobal.model.integration.GenesysAttachment;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.Set;

public interface GenesysImageManagerApiService {

	/** Stop sync process and clear state */
	void cancelSyncProcess();

	/** Stop sync process, but don't clear state */
	void pauseSyncProcess();

	SyncProcessStatus getSyncProcessStatus();

	Page<GenesysAttachmentDTO> getUploadList(Pageable page);

	Page<GenesysAttachmentDTO> getDownloadList(Pageable page);

	Page<GenesysAttachmentDTO> getUploadedList(Pageable page);

	SyncProcessStatus startSyncProcess(Set<String> instCodes);

	void syncUploadList() throws Exception;

	void syncDownloadList() throws Exception;

	SyncListProcessStatus getSyncListStatus(GenesysAttachment.ImageSyncList list);


	@Getter
	@Setter
	@Accessors(fluent = true)
	class SyncProcessStatus {
		public enum ProcessStatus {
			STARTED,
			DOWNLOADING,
			COMPARING,
			READY,
			FAILED
		}

		public ProcessStatus status;
		public String errorMessage;
		/// Track processing of CSV and of local attachments
		private SyncListProcessStatus listStatus;


		public SyncProcessStatus(ProcessStatus status) {
			assert (status != null);
			this.status = status;
		}

		public SyncProcessStatus(ProcessStatus status, String errorMessage) {
			assert (status != null);
			this.status = status;
			this.errorMessage = errorMessage;
		}
	}

	@Getter
	@Setter
	@Accessors(fluent = true)
	class SyncListProcessStatus {
		public enum ListProcessStatus {
			/** Running now */
			IN_PROGRESS,
			/** Stopped */
			STOPPED,
			/** Completed successfully */
			SYNCHRONIZED,
			/** Failed */
			FAILED
		}

		public ListProcessStatus status;
		public String errorMessage;
		public int errorCounter;
		public long totalElements;
    public int successCounter;

		public SyncListProcessStatus(ListProcessStatus status) {
			assert (status != null);
			this.status = status;
		}
	}
}