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

org.bimserver.ifc.compare.CompareService Maven / Gradle / Ivy

The newest version!
package org.bimserver.ifc.compare;

/******************************************************************************
 * Copyright (C) 2009-2019  BIMserver.org
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see {@literal}.
 *****************************************************************************/

import java.util.List;

import javax.activation.DataHandler;

import org.bimserver.interfaces.objects.SCompareType;
import org.bimserver.interfaces.objects.SDeserializerPluginConfiguration;
import org.bimserver.interfaces.objects.SDownloadResult;
import org.bimserver.interfaces.objects.SModelComparePluginConfiguration;
import org.bimserver.interfaces.objects.SObjectType;
import org.bimserver.interfaces.objects.SProject;
import org.bimserver.interfaces.objects.SRevision;
import org.bimserver.interfaces.objects.SSerializerPluginConfiguration;
import org.bimserver.interfaces.objects.SService;
import org.bimserver.models.store.ServiceDescriptor;
import org.bimserver.plugins.services.AbstractService;
import org.bimserver.plugins.services.BimServerClientInterface;
import org.bimserver.shared.exceptions.UserException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CompareService extends AbstractService {

	private static final Logger LOGGER = LoggerFactory.getLogger(CompareService.class);
	
	@Override
	public void newRevision(RunningService runningService, BimServerClientInterface bimServerClientInterface, long poid, long roid, String userToken, long soid, SObjectType settings) throws Exception {
		SRevision revision = bimServerClientInterface.getServiceInterface().getRevision(roid);
		if (revision.getServicesLinked().contains(soid)) {
			throw new UserException("Not running service on this revision because it was generated by the same service");
		}
		if (revision.getServiceId() == soid) {
			throw new UserException("Not running service on this revision because it was generated by the same service");
		}
		List allModelCompares = bimServerClientInterface.getPluginInterface().getAllModelCompares(true);
		SModelComparePluginConfiguration modelComparePlugin = null;
		for (SModelComparePluginConfiguration modelComparePluginConfiguration : allModelCompares) {
			if (modelComparePluginConfiguration.getName().equals("GUID based")) {
				modelComparePlugin = modelComparePluginConfiguration;
			}
		}
		if (modelComparePlugin == null) {
			throw new UserException("No GUID based model compare plugin found");
		}
		SProject project = bimServerClientInterface.getServiceInterface().getProjectByPoid(poid);
		if (project.getRevisions().size() < 2) {
			throw new UserException("At least 2 revision required to be able to run compare");
		}
		Long secondLastRoid = project.getRevisions().get(project.getRevisions().size() - 2);
		
		SSerializerPluginConfiguration serializerByContentType = bimServerClientInterface.getServiceInterface().getSerializerByContentType("application/ifc");
		
		Long topicId = bimServerClientInterface.getServiceInterface().downloadCompareResults(serializerByContentType.getOid(), secondLastRoid, roid, modelComparePlugin.getOid(), SCompareType.ALL, true);
		SDownloadResult downloadData = bimServerClientInterface.getServiceInterface().getDownloadData(topicId);
		DataHandler file = downloadData.getFile();
		
		SDeserializerPluginConfiguration suggestedDeserializerForExtension = bimServerClientInterface.getServiceInterface().getSuggestedDeserializerForExtension("ifc", poid);
		
		LOGGER.info("Using " + suggestedDeserializerForExtension.getName() + " as serializer");
		
		SService service = bimServerClientInterface.getServiceInterface().getService(soid);
				
		bimServerClientInterface.checkinSync(service.getWriteRevisionId(), "test", suggestedDeserializerForExtension.getOid(), false, -1, "", file.getInputStream());
	}

	@Override
	public void addRequiredRights(ServiceDescriptor serviceDescriptor) {
		serviceDescriptor.setWriteRevision(true);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy