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

com.bagri.server.hazelcast.task.model.ModelRegistrator Maven / Gradle / Ivy

The newest version!
package com.bagri.server.hazelcast.task.model;

import static com.bagri.server.hazelcast.serialize.TaskSerializationFactory.cli_factory_id;
import static com.bagri.server.hazelcast.serialize.TaskSerializationFactory.cli_RegisterModelTask;

import java.io.IOException;
import java.util.concurrent.Callable;

import org.springframework.beans.factory.annotation.Autowired;

import com.bagri.core.server.api.ContentModeler;
import com.bagri.server.hazelcast.impl.SchemaRepositoryImpl;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.IdentifiedDataSerializable;
import com.hazelcast.spring.context.SpringAware;

@SpringAware
public class ModelRegistrator implements Callable, IdentifiedDataSerializable {
	
	private String dataFormat;
	private String modelPath;
	private boolean singleModel;
	private transient SchemaRepositoryImpl xdmRepo;
	
	public ModelRegistrator() {
		//
	}
	
	public ModelRegistrator(String dataFormat, String modelPath, boolean singleModel) {
		this.dataFormat = dataFormat; 
		this.modelPath = modelPath;
		this.singleModel = singleModel;
	}

    @Autowired
	public void setXDMRepository(SchemaRepositoryImpl xdmRepo) {
		this.xdmRepo = xdmRepo;
	}
	
	@Override
	public Integer call() throws Exception {
		//int size = ((ModelManagementBase) modelMgr).getDocumentTypes().size();
		//Path path = Paths.get(schemaFile, null);
		//if (Files.isDirectory(path, null)) {

		ContentModeler cm = xdmRepo.getModeler(dataFormat);
		if (singleModel) {
			cm.registerModelUri(modelPath);
		} else {
			cm.registerModelUri(modelPath);
		}
			//modelMgr.registerSchemaUri(schemaFile);			
		//} else {
		//	modelMgr.registerSchemaUri(schemaFile);
		//}
		//return ((ModelManagementBase) modelMgr).getDocumentTypes().size() - size;
		return 1;
	}

	@Override
	public int getId() {
		return cli_RegisterModelTask;
	}

	@Override
	public int getFactoryId() {
		return cli_factory_id;
	}
	
	@Override
	public void readData(ObjectDataInput in) throws IOException {
		dataFormat = in.readUTF();
		modelPath = in.readUTF();
		singleModel = in.readBoolean();
	}
	
	@Override
	public void writeData(ObjectDataOutput out) throws IOException {
		out.writeUTF(dataFormat);
		out.writeUTF(modelPath);
		out.writeBoolean(singleModel);
	}

}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy