Search in sources :

Example 26 with Identifier

use of org.wso2.carbon.apimgt.api.model.Identifier in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addJoinCause.

public void addJoinCause(Set<Whitespace> ws, String identifier) {
    BLangForkJoin forkJoin = (BLangForkJoin) this.forkJoinNodesStack.peek();
    forkJoin.joinedBody = (BLangBlockStmt) this.blockNodeStack.pop();
    Set<Whitespace> varWS = removeNthFromLast(ws, 3);
    forkJoin.addWS(ws);
    forkJoin.joinResultVar = (BLangVariable) this.generateBasicVarNode((DiagnosticPos) this.typeNodeStack.peek().getPosition(), varWS, identifier, false);
}
Also used : BLangForkJoin(org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin) Whitespace(org.ballerinalang.model.Whitespace)

Example 27 with Identifier

use of org.wso2.carbon.apimgt.api.model.Identifier in project ballerina by ballerina-lang.

the class BLangPackageBuilder method endConnectorDef.

public void endConnectorDef(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean publicCon) {
    BLangConnector connectorNode = (BLangConnector) this.connectorNodeStack.pop();
    connectorNode.pos = pos;
    connectorNode.addWS(ws);
    connectorNode.setName(this.createIdentifier(identifier));
    if (publicCon) {
        connectorNode.flagSet.add(Flag.PUBLIC);
    }
    endEndpointDeclarationScope();
    this.compUnit.addTopLevelNode(connectorNode);
}
Also used : BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector)

Example 28 with Identifier

use of org.wso2.carbon.apimgt.api.model.Identifier in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addFieldToObject.

void addFieldToObject(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean exprAvailable, int annotCount, boolean isPrivate) {
    Set<Whitespace> wsForSemiColon = removeNthFromLast(ws, 0);
    BLangObject objectNode = (BLangObject) this.objectStack.peek();
    objectNode.addWS(wsForSemiColon);
    BLangVariable field = addVar(pos, ws, identifier, exprAvailable, annotCount);
    if (!isPrivate) {
        field.flagSet.add(Flag.PUBLIC);
    }
}
Also used : BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) Whitespace(org.ballerinalang.model.Whitespace) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 29 with Identifier

use of org.wso2.carbon.apimgt.api.model.Identifier in project ballerina by ballerina-lang.

the class PackageLoader method loadAndDefinePackage.

public BLangPackage loadAndDefinePackage(BLangIdentifier orgName, List<BLangIdentifier> pkgNameComps, BLangIdentifier version) {
    // TODO This method is only used by the composer. Can we refactor the composer code?
    List<Name> nameComps = pkgNameComps.stream().map(identifier -> names.fromIdNode(identifier)).collect(Collectors.toList());
    PackageID pkgID = new PackageID(names.fromIdNode(orgName), nameComps, names.fromIdNode(version));
    return loadAndDefinePackage(pkgID);
}
Also used : SystemPackageRepositoryProvider(org.ballerinalang.spi.SystemPackageRepositoryProvider) Arrays(java.util.Arrays) PackageSource(org.ballerinalang.repository.PackageSource) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) PROJECT_DIR(org.ballerinalang.compiler.CompilerOptionName.PROJECT_DIR) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) Converter(org.wso2.ballerinalang.compiler.packaging.converters.Converter) Names(org.wso2.ballerinalang.compiler.util.Names) RepoHierarchy(org.wso2.ballerinalang.compiler.packaging.RepoHierarchy) URI(java.net.URI) Path(java.nio.file.Path) ProjectSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo) PackageID(org.ballerinalang.model.elements.PackageID) Set(java.util.Set) ServiceLoader(java.util.ServiceLoader) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Manifest(org.ballerinalang.toml.model.Manifest) OFFLINE(org.ballerinalang.compiler.CompilerOptionName.OFFLINE) Resolution(org.wso2.ballerinalang.compiler.packaging.Resolution) RepoHierarchyBuilder(org.wso2.ballerinalang.compiler.packaging.RepoHierarchyBuilder) Optional(java.util.Optional) SymbolEnter(org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolEnter) CompilerOptions(org.wso2.ballerinalang.compiler.util.CompilerOptions) ManifestProcessor(org.ballerinalang.toml.parser.ManifestProcessor) RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) ArrayList(java.util.ArrayList) Dependency(org.ballerinalang.toml.model.Dependency) RepoHierarchyBuilder.node(org.wso2.ballerinalang.compiler.packaging.RepoHierarchyBuilder.node) HomeRepoUtils(org.wso2.ballerinalang.util.HomeRepoUtils) PackageRepository(org.ballerinalang.repository.PackageRepository) Repo(org.wso2.ballerinalang.compiler.packaging.repo.Repo) TreeBuilder(org.ballerinalang.model.TreeBuilder) ProgramingSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProgramingSourceRepo) ProjectDirs(org.wso2.ballerinalang.compiler.util.ProjectDirs) StreamSupport(java.util.stream.StreamSupport) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangCompilerException(org.ballerinalang.compiler.BLangCompilerException) Name(org.wso2.ballerinalang.compiler.util.Name) ZipRepo(org.wso2.ballerinalang.compiler.packaging.repo.ZipRepo) PackageEntity(org.ballerinalang.repository.PackageEntity) Parser(org.wso2.ballerinalang.compiler.parser.Parser) Paths(java.nio.file.Paths) GenericPackageSource(org.wso2.ballerinalang.compiler.packaging.GenericPackageSource) CacheRepo(org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo) Collections(java.util.Collections) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) PackageID(org.ballerinalang.model.elements.PackageID) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 30 with Identifier

use of org.wso2.carbon.apimgt.api.model.Identifier in project product-iots by wso2.

the class DeviceTypeServiceImpl method getSensorStats.

/**
 * Retrieve Sensor data for the given time period.
 *
 * @param deviceId unique identifier for given device type instance
 * @param from     starting time
 * @param to       ending time
 * @return response with List<SensorRecord> object which includes sensor data which is requested
 */
@Path("device/stats/{deviceId}")
@GET
@Consumes("application/json")
@Produces("application/json")
public Response getSensorStats(@PathParam("deviceId") String deviceId, @QueryParam("from") long from, @QueryParam("to") long to, @QueryParam("sensorType") String sensorType) {
    String fromDate = String.valueOf(from);
    String toDate = String.valueOf(to);
    String query = "meta_deviceId:" + deviceId + " AND meta_deviceType:" + DeviceTypeConstants.DEVICE_TYPE + " AND meta_time : [" + fromDate + " TO " + toDate + "]";
    String sensorTableName = null;
    if (sensorType.equals(DeviceTypeConstants.SENSOR_TYPE1)) {
        sensorTableName = DeviceTypeConstants.SENSOR_TYPE1_EVENT_TABLE;
    } else if (sensorType.equals(DeviceTypeConstants.SENSOR_TYPE2)) {
        sensorTableName = DeviceTypeConstants.SENSOR_TYPE2_EVENT_TABLE;
    }
    try {
        if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId, DeviceTypeConstants.DEVICE_TYPE))) {
            return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
        }
        if (sensorTableName != null) {
            List<SortByField> sortByFields = new ArrayList<>();
            SortByField sortByField = new SortByField("meta_time", SortType.ASC);
            sortByFields.add(sortByField);
            List<SensorRecord> sensorRecords = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields);
            return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecords).build();
        }
    } catch (AnalyticsException e) {
        String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
        log.error(errorMsg);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build();
    } catch (DeviceAccessAuthorizationException e) {
        log.error(e.getErrorMessage(), e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
    return Response.status(Response.Status.BAD_REQUEST).build();
}
Also used : SortByField(org.wso2.carbon.analytics.dataservice.commons.SortByField) DeviceAccessAuthorizationException(org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException) AnalyticsException(org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException) ArrayList(java.util.ArrayList) SensorRecord(org.wso2.iot.sampledevice.api.dto.SensorRecord) DeviceIdentifier(org.wso2.carbon.device.mgt.common.DeviceIdentifier) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)118 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)83 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)66 API (org.wso2.carbon.apimgt.api.model.API)42 Resource (org.wso2.carbon.registry.core.Resource)40 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)39 Test (org.junit.Test)36 PreparedStatement (java.sql.PreparedStatement)34 SQLException (java.sql.SQLException)34 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)34 Connection (java.sql.Connection)33 UserStoreException (org.wso2.carbon.user.core.UserStoreException)31 ResultSet (java.sql.ResultSet)29 ArrayList (java.util.ArrayList)29 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)29 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)27 IOException (java.io.IOException)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)26 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)25 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)24