blob: 2d76ac57f7a83601dfe4f9cd2acecd8f00cd056d [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2015-2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
package org.eclipse.mdm.businessobjects.boundary;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ejb.Stateless;
import javax.inject.Inject;
import org.eclipse.mdm.api.base.adapter.ModelManager;
import org.eclipse.mdm.api.base.model.MDMLocalization;
import org.eclipse.mdm.api.base.query.DataAccessException;
import org.eclipse.mdm.businessobjects.control.MDMEntityAccessException;
import org.eclipse.mdm.businessobjects.utils.ServiceUtils;
import org.eclipse.mdm.connector.boundary.ConnectorService;
@Stateless
public class LocalizationService {
@Inject
private ConnectorService connectorService;
public List<MDMLocalization> localize(String sourceName) {
try {
return this.connectorService.getContextByName(sourceName).getEntityManager()
.orElseThrow(() -> new MDMEntityAccessException("Entity manager not present!"))
.loadAll(MDMLocalization.class);
} catch (DataAccessException e) {
throw new MDMEntityAccessException(e.getMessage(), e);
}
}
public Map<String, String> getDefaultMimeTypes(String sourceName) {
try {
ModelManager mm = this.connectorService.getContextByName(sourceName).getModelManager()
.orElseThrow(() -> new MDMEntityAccessException("Model manager not present!"));
Map<String, String> map = new HashMap<>();
mm.listEntityTypes().stream()
.forEach(et -> map.put(ServiceUtils.workaroundForTypeMapping(et.getName()), mm.getMimeType(et)));
return map;
} catch (DataAccessException e) {
throw new MDMEntityAccessException(e.getMessage(), e);
}
}
}