package eu.dnetlib.utils;

import java.util.Set;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;

import eu.dnetlib.clients.is.DnetSchemaId;
import eu.dnetlib.clients.is.InformationServiceClient;
import eu.dnetlib.exceptions.DnetGenericException;

@Component
@Conditional(RemoteInformationServiceCondition.class)
public class GenericBulkResourceImporter extends AbstractBulkResourceImporter {

	@Autowired
	private InformationServiceClient isClient;

	@Override
	@PostConstruct
	public void bulkImport() throws DnetGenericException {
		super.bulkImport();
	}

	@Override
	protected void registerProfile(final String profile) {
		isClient.bulkRegister(profile);
	}

	@Override
	protected void registerSchema(final DnetSchemaId schemaId, final String schema) {
		isClient.registerSchema(schemaId, schema);
	}

	@Override
	protected boolean isProfileAlreadyRegistered(final String profId) throws Exception {
		return isClient.find("//RESOURCE_IDENTIFIER[@value = '" + profId + "']").size() > 0;
	}

	@Override
	protected Set<DnetSchemaId> listAlreadyRegisterdSchemas() throws Exception {
		return isClient.listSchemas();
	}

}
