blob: 32e97d54bd86e761d5b67cc230a9970206ec74b7 [file] [log] [blame]
package templates.m2m
import templates.AbstractAmaltheaInchronTransformer
import com.inchron.realtime.root.model.ModelFactory
import org.eclipse.app4mc.amalthea.model.Amalthea
import com.inchron.realtime.root.model.Model
import java.text.SimpleDateFormat
import java.text.DateFormat
import java.util.Date
import java.util.Locale
import org.eclipse.app4mc.amalthea.model.StringObject
import com.google.inject.Inject
import templates.m2m.hw.HWTransformer
import templates.m2m.os.OSTransformer
import templates.m2m.mapping.MappingTransformer
import templates.m2m.stimuli.StimuliTransformer
import templates.m2m.sw.SWTransformer
import com.google.inject.Singleton
@Singleton
class ModelTransformer extends AbstractAmaltheaInchronTransformer{
@Inject extension HWTransformer hwTransformer
@Inject extension OSTransformer osTransformer
@Inject extension MappingTransformer mappingTransformer
@Inject extension StimuliTransformer stimuliTransformer
@Inject extension SWTransformer swTransformer
/**
* This method creates the object of INCHRON Model element, and fills it by invoking various transformations
*/
def create ModelFactory.eINSTANCE.createModel createInchronModel(Amalthea amalthea) {
customObjsStore.injectMembers(Amalthea , amalthea)
customObjsStore.injectMembers(Model , it)
transformMetaInfo(amalthea, it)
it.name = "Model"
hwTransformer.transfromHWModel(amalthea.hwModel, it)
osTransformer.transfromOSModel(amalthea.osModel, it)
mappingTransformer.transfromMappingModel(amalthea.mappingModel, it)
stimuliTransformer.transformStimuliModel(amalthea.stimuliModel, it)
swTransformer.transformSWModel(amalthea.swModel, it)
}
/**
* Create and fill the INCHRON model's GeneralInfo with meta information,
* mainly from the Amalthea customProperties map.
* @Note: customProperties keys used here are currently informal/not specified.
*/
def transformMetaInfo(Amalthea amalthea, Model inchronModel) {
var DateFormat dateFormat = new SimpleDateFormat("dd.MMMM.yyyy", Locale.ENGLISH)
var info = ModelFactory.eINSTANCE.createGeneralInfo()
info.setCreator(("Amlt2Inchron " + amalthea.getVersion() + " " + new Date()).toString())
info.setVersion("1")
val value = amalthea.getCustomProperties().get("Date_Last_Modified")
if (value instanceof StringObject) {
val date = (value as StringObject).getValue()
if (date !== null)
info.setModifiedDate(dateFormat.parse(date))
}
val author = amalthea.getCustomProperties().get("Author")
if (author instanceof StringObject)
info.setAuthor((author as StringObject).getValue())
val descr = amalthea.getCustomProperties().get("Description")
if (descr instanceof StringObject)
info.setDescription((descr as StringObject).getValue())
inchronModel.setGeneralInfo(info)
}
}