blob: d7aa35c7c906e1d9129dd5200cfe968529a24488 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.mondrian;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.felix.service.command.Descriptor;
import org.apache.felix.service.command.Parameter;
import org.eclipse.osbp.mondrian.api.IMondrianManager;
import org.eclipse.osbp.mondrian.api.IMondrianService;
import org.eclipse.osbp.runtime.common.shell.ICommandConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.slf4j.Logger;
@Component(service = Object.class, name = "cube.commands", property = {
ICommandConstants.COMMAND_SCOPE + "=osbp",
ICommandConstants.COMMAND_FUNCTION + "=cubes",
ICommandConstants.COMMAND_FUNCTION + "=cube" })
public class Commands {
private static final Logger LOGGER = org.slf4j.LoggerFactory
.getLogger(Commands.class);
IMondrianManager service;
@Descriptor("Lists all cube services.")
public List<String> cubes() {
List<String> result = new ArrayList<>();
for (IMondrianService s : service.getAllServices()) {
result.add(String.format("package: %s url: %s", s.getPackageName(),
s.getMondrianCatalogURL().toString()));
}
return result;
}
@Descriptor("Lists the cube.xml for a specified cube package name.")
public List<String> cube(
@Descriptor("shows the cube.xml") @Parameter(absentValue = "false", presentValue = "true", names = {
"-xml", "--xml" }) boolean xml,
@Descriptor("The package name of the cube") String packageName) {
List<String> result = new ArrayList<>();
IMondrianService s = service.getService(packageName);
if (s == null) {
result.add("No cube available for packageName");
} else {
if (xml) {
BufferedReader br = null;
try {
String line;
br = new BufferedReader(new InputStreamReader(s
.getMondrianCatalogURL().openStream()));
while ((line = br.readLine()) != null) {
result.add(line);
}
} catch (IOException e) {
LOGGER.error("{}", e);
} finally {
try {
if (br != null)
br.close();
} catch (IOException ex) {
LOGGER.error("{}", ex);
}
}
}
}
return result;
}
@Reference(cardinality = ReferenceCardinality.MANDATORY)
void bindIMetadataBuilderService(IMondrianManager service) {
this.service = service;
}
void unbindIMetadataBuilderService(IMondrianManager service) {
this.service = service;
}
}