当前位置: 首页>>代码示例>>Java>>正文


Java BodyParser.Raw方法代码示例

本文整理汇总了Java中play.mvc.BodyParser.Raw方法的典型用法代码示例。如果您正苦于以下问题:Java BodyParser.Raw方法的具体用法?Java BodyParser.Raw怎么用?Java BodyParser.Raw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在play.mvc.BodyParser的用法示例。


在下文中一共展示了BodyParser.Raw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleFileUploadRaw

import play.mvc.BodyParser; //导入方法依赖的package包/类
@BodyParser.Of (value = BodyParser.Raw.class, maxLength = 2 * 1024 * 1024)
public static Result handleFileUploadRaw () {
	final String content = request ().body ().asRaw () != null 
			? handleFileUpload (request ().body ().asRaw ().asFile ()) 
			: null;
			
	final ObjectNode result = Json.newObject ();
	if (content == null) {
		result.put ("valid", false);
	} else {
		result.put ("valid", true);
		result.put ("textContent", content);
	}
	
	return ok (result);
}
 
开发者ID:IDgis,项目名称:geo-publisher,代码行数:17,代码来源:Styles.java

示例2: post

import play.mvc.BodyParser; //导入方法依赖的package包/类
@BodyParser.Of(BodyParser.Raw.class)
public static Promise<Result> post(String protocol) throws Throwable {
  String contentTypeHeader = request().getHeader("content-type");
  ContentType contentType = ContentType.parse(contentTypeHeader);
  if (!CONTENT_TYPE.equals(contentType.getMimeType())) {
    throw new RuntimeException("Unable to handle content-type " + contentType + "; "
        + CONTENT_TYPE + " is expected");
  }

  AvroPlugin plugin = AvroPlugin.getInstance();
  Class<?> protocolClass = Play.application().classloader().loadClass(protocol);
  Object implementation = plugin.getProtocolImplementations().get(protocolClass);
  byte[] bytes = request().body().asRaw().asBytes();

  List<ByteBuffer> buffers = AsyncHttpTransceiver.readBuffers(new ByteArrayInputStream(bytes));
  AsyncResponder responder = new AsyncResponder(protocolClass, implementation);
  Promise<List<ByteBuffer>> response = responder.asyncRespond(buffers);
  return response.map(result -> {
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    try {
      AsyncHttpTransceiver.writeBuffers(result, outStream);
    } finally {
      outStream.close();
    }
    return Results.ok(outStream.toByteArray());
  });
}
 
开发者ID:tfeng,项目名称:play-plugins,代码行数:28,代码来源:BinaryIpcController.java

示例3: validateSld

import play.mvc.BodyParser; //导入方法依赖的package包/类
@BodyParser.Of (value = BodyParser.Raw.class, maxLength = 2 * 1024 * 1024)
public static Result validateSld (String sldScheme) {
	final String content = request ().body ().asRaw () != null
			? handleFileUpload (request ().body ().asRaw ().asFile ())
			: null;
			
	final ObjectNode result = Json.newObject ();
	if (content == null) {
		result.put ("valid", false);
		result.put ("message", Domain.message ("web.application.page.styles.form.field.definition.validation.cantValidate"));
	} else {
		final XmlError xmlError = isValidXml (content, sldScheme);
		
		if (xmlError != null) {
			result.put ("valid", false);
			result.put ("message", xmlError.message);
			if (xmlError.line != null) {
				result.put ("line", (int) xmlError.line);
			}
		} else {
			result.put ("valid", true);
			result.put ("message", Domain.message ("web.application.page.styles.form.field.definition.validation.valid"));
		}
	}
	
	return ok (result);
}
 
开发者ID:IDgis,项目名称:geo-publisher,代码行数:28,代码来源:Styles.java

示例4: data

import play.mvc.BodyParser; //导入方法依赖的package包/类
/**
 * Add a KPI data.
 * 
 * @param uid
 *            the KPI definition uid
 */
@ApiAuthentication(additionalCheck = ApiAuthenticationBizdockCheck.class)
@ApiOperation(value = "Add KPI data", notes = "Add data (for main, additional 1 and additional 2 values) for a KPI", response = KpiDataRequest.class,
        httpMethod = "POST")
@ApiImplicitParams({ @ApiImplicitParam(name = "body", value = "A KPI data", required = true, dataType = "KpiDataRequest", paramType = "body") })
@ApiResponses(value = { @ApiResponse(code = 204, message = "success"), @ApiResponse(code = 400, message = "bad request", response = ApiError.class),
        @ApiResponse(code = 404, message = "not found", response = ApiError.class),
        @ApiResponse(code = 500, message = "error", response = ApiError.class) })
@BodyParser.Of(BodyParser.Raw.class)
public Result addKpiData(@ApiParam(value = "KPI uid", required = true) @PathParam("uid") String uid) {
    try {

        // Json to object
        JsonNode json = getRequestBodyAsJsonNode(request());

        // fill the play form
        Form<KpiDataRequest> kpiDataRequestForm = kpiDataRequestFormTemplate.bind(json);

        // if errors
        if (kpiDataRequestForm.hasErrors()) {
            Map<String, List<ValidationError>> allErrors = kpiDataRequestForm.errors();
            String errorMsg = ApiError.getValidationErrorsMessage(getMessagesPlugin(), allErrors);
            return getJsonErrorResponse(new ApiError(400, errorMsg));
        }

        // Validation Form
        KpiDataRequest kpiDataRequest = kpiDataRequestForm.get();

        try {
            getKpiService().addData(uid, kpiDataRequest.objectId, kpiDataRequest.timestamp, kpiDataRequest.mainValue, kpiDataRequest.additional1Value,
                    kpiDataRequest.additional2Value);
        } catch (KpiServiceException kpiE) {
            return getJsonErrorResponse(new ApiError(kpiE.getHttpCode(), kpiE.getMessage()));
        }

        // return json success
        return noContent();

    } catch (Exception e) {
        return getJsonErrorResponse(new ApiError(500, "Unexpected error", e));
    }
}
 
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:48,代码来源:KpiApiController.java

示例5: updateRequirementStatus

import play.mvc.BodyParser; //导入方法依赖的package包/类
/**
 * Update a requirement status.
 * 
 * WARNING: If an optional attribute is not given, then its current value
 * will be settled to null.
 * 
 * @param id
 *            the requirement status id
 * 
 * @return the JSON object of the corresponding requirement status.
 */
@ApiAuthentication(additionalCheck = ApiAuthenticationBizdockCheck.class)
@ApiOperation(value = "Update the specified Requirement Status, default for empty fields : null", notes = "Update a requirement status", response = RequirementStatusRequest.class, httpMethod = "PUT")
@ApiImplicitParams({
        @ApiImplicitParam(name = "body", value = "A input Requirement Status object", required = true, dataType = "RequirementStatusRequest", paramType = "body") })
@ApiResponses(value = { @ApiResponse(code = 200, message = "success"), @ApiResponse(code = 400, message = "bad request", response = ApiError.class),
        @ApiResponse(code = 404, message = "not found", response = ApiError.class),
        @ApiResponse(code = 500, message = "error", response = ApiError.class) })
@BodyParser.Of(BodyParser.Raw.class)
public Result updateRequirementStatus(@ApiParam(value = "A requirement status id", required = true) @PathParam("id") Long id) {
    try {

        RequirementStatus requirementStatus = RequirementDAO.getRequirementStatusById(id);
        if (requirementStatus == null) {
            return getJsonErrorResponse(new ApiError(404, "The Requirement Status with the specified id is not found"));
        }

        // Json to object
        JsonNode json = getRequestBodyAsJsonNode(request());

        // fill the play form
        Form<RequirementStatusRequest> requirementStatusRequestForm = requirementStatusRequestFormTemplate.bind(json);

        // if errors
        if (requirementStatusRequestForm.hasErrors()) {
            // get errors
            Map<String, List<ValidationError>> allErrors = requirementStatusRequestForm.errors();
            // get errors to String Format
            String errorMsg = ApiError.getValidationErrorsMessage(getMessagesPlugin(), allErrors);
            return getJsonErrorResponse(new ApiError(404, errorMsg));
        }

        // Validation Form
        RequirementStatusRequest requirementStatusRequest = requirementStatusRequestForm.get();

        // fill to match with DB
        requirementStatus.name = requirementStatusRequest.name;
        requirementStatus.description = requirementStatusRequest.description;
        requirementStatus.type = requirementStatusRequest.type;

        requirementStatus.save();

        // json success
        return getJsonSuccessResponse(requirementStatus);

    } catch (Exception e) {
        return getJsonErrorResponse(new ApiError(500, "Unexpected error", e));
    }
}
 
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:60,代码来源:RequirementStatusApiController.java

示例6: createPortfolioEntryRiskType

import play.mvc.BodyParser; //导入方法依赖的package包/类
/**
 * Create a portfolio entry risk type.
 */
@ApiAuthentication(additionalCheck = ApiAuthenticationBizdockCheck.class)
@ApiOperation(value = "Create a PE Risk Type", notes = "Create a Portfolio Entry Risk Type", response = PortfolioEntryRiskTypeRequest.class, httpMethod = "POST")
@ApiImplicitParams({
        @ApiImplicitParam(name = "body", value = "A PE Risk type", required = true, dataType = "PortfolioEntryRiskTypeRequest", paramType = "body") })
@ApiResponses(value = { @ApiResponse(code = 201, message = "success"), @ApiResponse(code = 400, message = "bad request", response = ApiError.class),
        @ApiResponse(code = 500, message = "error", response = ApiError.class) })
@BodyParser.Of(BodyParser.Raw.class)
public Result createPortfolioEntryRiskType() {
    try {

        // Json to object
        JsonNode json = getRequestBodyAsJsonNode(request());

        // fill the play form
        Form<PortfolioEntryRiskTypeRequest> portfolioEntryRiskTypeRequestForm = portfolioEntryRiskTypeRequestFormTemplate.bind(json);

        // if errors
        if (portfolioEntryRiskTypeRequestForm.hasErrors()) {
            // get errors
            Map<String, List<ValidationError>> allErrors = portfolioEntryRiskTypeRequestForm.errors();
            // get errors to String Format
            String errorMsg = ApiError.getValidationErrorsMessage(getMessagesPlugin(), allErrors);
            return getJsonErrorResponse(new ApiError(400, errorMsg));
        }

        // Validation Form
        PortfolioEntryRiskTypeRequest portfolioEntryRiskTypeRequest = portfolioEntryRiskTypeRequestForm.get();

        PortfolioEntryRiskType portfolioEntryRiskType = new PortfolioEntryRiskType();

        // fill to match with DB
        portfolioEntryRiskType.name = portfolioEntryRiskTypeRequest.name;
        portfolioEntryRiskType.description = portfolioEntryRiskTypeRequest.description;
        portfolioEntryRiskType.selectable = portfolioEntryRiskTypeRequest.selectable;

        portfolioEntryRiskType.save();

        // return json success
        return getJsonSuccessCreatedResponse(portfolioEntryRiskType);

    } catch (Exception e) {
        return getJsonErrorResponse(new ApiError(500, "Unexpected error", e));
    }
}
 
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:48,代码来源:PortfolioEntryRiskTypeApiController.java

示例7: udpatePortfolioEntryRiskType

import play.mvc.BodyParser; //导入方法依赖的package包/类
/**
 * Update a portoflio entry Risk type.
 * 
 * WARNING: If an optional attribute is not given, then its current value
 * will be settled to null.
 * 
 * @param id
 *            the PE Risk type id
 * 
 * @return the JSON object of the corresponding PE Risk type.
 */
@ApiAuthentication(additionalCheck = ApiAuthenticationBizdockCheck.class)
@ApiOperation(value = "Update the specified Portfolio Entry Risk Type, default for empty fields : null", notes = "Update a Portfolio Entry Risk Type", response = PortfolioEntryRiskTypeRequest.class, httpMethod = "PUT")
@ApiImplicitParams({
        @ApiImplicitParam(name = "body", value = "A input Portfolio Entry Risk Type object", required = true, dataType = "PortfolioEntryRiskTypeRequest", paramType = "body") })
@ApiResponses(value = { @ApiResponse(code = 200, message = "success"), @ApiResponse(code = 400, message = "bad request", response = ApiError.class),
        @ApiResponse(code = 404, message = "not found", response = ApiError.class),
        @ApiResponse(code = 500, message = "error", response = ApiError.class) })
@BodyParser.Of(BodyParser.Raw.class)
public Result udpatePortfolioEntryRiskType(@ApiParam(value = "A PE Risk type id", required = true) @PathParam("id") Long id) {
    try {

        PortfolioEntryRiskType portfolioEntryRiskType = PortfolioEntryRiskDao.getPERiskTypeById(id);
        if (portfolioEntryRiskType == null) {
            return getJsonErrorResponse(new ApiError(404, "The PE Risk Type with the specified id is not found"));
        }

        // Json to object
        JsonNode json = getRequestBodyAsJsonNode(request());

        // fill the play form
        Form<PortfolioEntryRiskTypeRequest> portfolioEntryRiskTypeRequestForm = portfolioEntryRiskTypeRequestFormTemplate.bind(json);

        // if errors
        if (portfolioEntryRiskTypeRequestForm.hasErrors()) {
            // get errors
            Map<String, List<ValidationError>> allErrors = portfolioEntryRiskTypeRequestForm.errors();
            // get errors to String Format
            String errorMsg = ApiError.getValidationErrorsMessage(getMessagesPlugin(), allErrors);
            return getJsonErrorResponse(new ApiError(404, errorMsg));
        }

        // Validation Form
        PortfolioEntryRiskTypeRequest portfolioEntryRiskTypeRequest = portfolioEntryRiskTypeRequestForm.get();

        // Save
        // fill to match with DB
        portfolioEntryRiskType.name = portfolioEntryRiskTypeRequest.name;
        portfolioEntryRiskType.description = portfolioEntryRiskTypeRequest.description;
        portfolioEntryRiskType.selectable = portfolioEntryRiskTypeRequest.selectable;

        portfolioEntryRiskType.save();

        // json success
        return getJsonSuccessResponse(portfolioEntryRiskType);

    } catch (Exception e) {
        return getJsonErrorResponse(new ApiError(500, "Unexpected error", e));
    }
}
 
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:61,代码来源:PortfolioEntryRiskTypeApiController.java

示例8: updatePortfolio

import play.mvc.BodyParser; //导入方法依赖的package包/类
/**
 * Update a portfolio.
 * 
 * WARNING: If an optional attribute is not given, then its current value
 * will be settled to null.
 * 
 * @param id
 *            the portfolio id
 * 
 * @return the JSON object of the corresponding portfolio entry.
 */
@ApiAuthentication(additionalCheck = ApiAuthenticationBizdockCheck.class)
@ApiOperation(value = "Update the specified Portfolio, default for empty fields : null", notes = "Update a Portfolio", response = PortfolioRequest.class, httpMethod = "PUT")
@ApiImplicitParams({ @ApiImplicitParam(name = "body", value = "A portfolio", required = true, dataType = "PortfolioRequest", paramType = "body") })
@ApiResponses(value = { @ApiResponse(code = 200, message = "success"), @ApiResponse(code = 400, message = "bad request", response = ApiError.class),
        @ApiResponse(code = 404, message = "not found", response = ApiError.class),
        @ApiResponse(code = 500, message = "error", response = ApiError.class) })
@BodyParser.Of(BodyParser.Raw.class)
public Result updatePortfolio(@ApiParam(value = "A portfolio id", required = true) @PathParam("id") Long id) {
    try {

        Portfolio portfolio = PortfolioDao.getPortfolioById(id);
        // check if portfolio exists
        if (portfolio == null) {
            return getJsonErrorResponse(new ApiError(404, "The Portfolio with the specified id is not found"));
        }

        // Json to object
        JsonNode json = getRequestBodyAsJsonNode(request());

        // fill the play form
        Form<PortfolioRequest> portfolioRequestForm = portfolioRequestFormTemplate.bind(json);

        // if errors
        if (portfolioRequestForm.hasErrors()) {
            // get errors
            Map<String, List<ValidationError>> allErrors = portfolioRequestForm.errors();
            // get errors to String Format
            String errorMsg = ApiError.getValidationErrorsMessage(getMessagesPlugin(), allErrors);
            return getJsonErrorResponse(new ApiError(400, errorMsg));
        }

        // Get the form data
        PortfolioRequest portfolioRequest = portfolioRequestForm.get();

        // fill to match with DB
        portfolio.name = portfolioRequest.name;
        portfolio.isActive = portfolioRequest.isActive;
        portfolio.manager = ActorDao.getActorById(portfolioRequest.managerId);
        portfolio.portfolioType = PortfolioDao.getPortfolioTypeById(portfolioRequest.portfolioTypeId);
        portfolio.refId = portfolioRequest.refId;
        portfolio.save();

        // json success
        return getJsonSuccessResponse(portfolio);

    } catch (Exception e) {
        return getJsonErrorResponse(new ApiError(500, "Unexpected error", e));
    }
}
 
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:61,代码来源:PortfolioApiController.java

示例9: createActorType

import play.mvc.BodyParser; //导入方法依赖的package包/类
/**
 * Create an actor type.
 */
@ApiAuthentication(additionalCheck = ApiAuthenticationBizdockCheck.class)
@ApiOperation(value = "Create an Actor Type", notes = "Create an Actor Type", response = ActorTypeRequest.class, httpMethod = "POST")
@ApiImplicitParams({ @ApiImplicitParam(name = "body", value = "An actor type", required = true, dataType = "ActorTypeRequest", paramType = "body") })
@ApiResponses(value = { @ApiResponse(code = 201, message = "success"), @ApiResponse(code = 400, message = "bad request", response = ApiError.class),
        @ApiResponse(code = 500, message = "error", response = ApiError.class) })
@BodyParser.Of(BodyParser.Raw.class)
public Result createActorType() {
    try {

        // Json to object
        JsonNode json = getRequestBodyAsJsonNode(request());

        // fill the play form
        Form<ActorTypeRequest> actorTypeRequestForm = actorTypeRequestFormTemplate.bind(json);

        // if errors
        if (actorTypeRequestForm.hasErrors()) {
            // get errors
            Map<String, List<ValidationError>> allErrors = actorTypeRequestForm.errors();
            // get errors to String Format
            String errorMsg = ApiError.getValidationErrorsMessage(getMessagesPlugin(), allErrors);
            return getJsonErrorResponse(new ApiError(400, errorMsg));
        }

        // Validation Form
        ActorTypeRequest actorTypeRequest = actorTypeRequestForm.get();

        // Save actor type
        ActorType actorType = new ActorType();

        // fill to match with DB
        actorType.name = actorTypeRequest.name;
        actorType.description = actorTypeRequest.description;
        actorType.refId = actorTypeRequest.refId;
        actorType.selectable = actorTypeRequest.selectable;

        actorType.save();

        // return json success
        return getJsonSuccessCreatedResponse(actorType);

    } catch (Exception e) {
        return getJsonErrorResponse(new ApiError(500, "Unexpected error", e));
    }
}
 
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:49,代码来源:ActorTypeApiController.java

示例10: updateOrgUnit

import play.mvc.BodyParser; //导入方法依赖的package包/类
/**
 * Update an org unit.
 * 
 * WARNING: If an optional attribute is not given, then its current value
 * will be settled to null.
 * 
 * @param id
 *            the org unit id
 * 
 * @return the JSON object of the corresponding org unit.
 */
@ApiAuthentication(additionalCheck = ApiAuthenticationBizdockCheck.class)
@ApiOperation(value = "Update the specified OrgUnit, default for empty fields : null", notes = "Update an OrgUnit", response = OrgUnitRequest.class, httpMethod = "PUT")
@ApiImplicitParams({ @ApiImplicitParam(name = "body", value = "An OrgUnit", required = true, dataType = "OrgUnitRequest", paramType = "body") })
@ApiResponses(value = { @ApiResponse(code = 200, message = "success"), @ApiResponse(code = 400, message = "bad request", response = ApiError.class),
        @ApiResponse(code = 404, message = "not found", response = ApiError.class),
        @ApiResponse(code = 500, message = "error", response = ApiError.class) })
@BodyParser.Of(BodyParser.Raw.class)
public Result updateOrgUnit(@ApiParam(value = "id", required = true) @PathParam("id") Long id) {
    try {

        // check if orgunit exist
        if (OrgUnitDao.getOrgUnitById(id) == null) {
            return getJsonErrorResponse(new ApiError(404, "The Org Unit with the specified id is not found"));
        }

        // Json to object
        JsonNode json = getRequestBodyAsJsonNode(request());

        // fill the play form
        Form<OrgUnitRequest> orgUnitRequestForm = orgUnitRequestFormTemplate.bind(json);

        // if errors
        if (orgUnitRequestForm.hasErrors()) {
            // get errors
            Map<String, List<ValidationError>> allErrors = orgUnitRequestForm.errors();
            // get errors to String Format
            String errorMsg = ApiError.getValidationErrorsMessage(getMessagesPlugin(), allErrors);
            return getJsonErrorResponse(new ApiError(404, errorMsg));
        }

        // Validation Form
        OrgUnitRequest orgUnitRequest = orgUnitRequestForm.get();

        // Save OrgUnit
        OrgUnit orgUnit = OrgUnitDao.getOrgUnitById(id);

        // fill to match with DB
        orgUnit.refId = orgUnitRequest.refId;
        orgUnit.name = orgUnitRequest.name;
        orgUnit.isActive = orgUnitRequest.isActive;
        orgUnit.canSponsor = orgUnitRequest.canSponsor;
        orgUnit.canDeliver = orgUnitRequest.canDeliver;
        orgUnit.orgUnitType = OrgUnitDao.getOrgUnitTypeById(orgUnitRequest.orgUnitTypeId);
        orgUnit.manager = ActorDao.getActorById(orgUnitRequest.managerId);
        orgUnit.parent = OrgUnitDao.getOrgUnitById(orgUnitRequest.parentId);

        orgUnit.save();

        // json success
        return getJsonSuccessResponse(orgUnit);

    } catch (Exception e) {
        return getJsonErrorResponse(new ApiError(500, "Unexpected error", e));
    }
}
 
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:67,代码来源:OrgUnitApiController.java

示例11: updatePurchaseOrderLineShipmentStatusType

import play.mvc.BodyParser; //导入方法依赖的package包/类
/**
 * Update a purchase order line shipment status type.
 * 
 * WARNING: If an optional attribute is not given, then its current value
 * will be settled to null.
 * 
 * @param id
 *            the purchase order line shipment status type id
 * 
 * @return the JSON object of the corresponding purchase order.
 */
@ApiAuthentication(additionalCheck = ApiAuthenticationBizdockCheck.class)
@ApiOperation(value = "Update the specified Purchase Order, default for empty fields : null", notes = "Update a Purchase Order", response = PurchaseOrderLineShipmentStatusTypeRequest.class, httpMethod = "PUT")
@ApiImplicitParams({
        @ApiImplicitParam(name = "body", value = "An input purchase order line shipment status type object", required = true, dataType = "PurchaseOrderLineShipmentStatusTypeRequest", paramType = "body") })
@ApiResponses(value = { @ApiResponse(code = 200, message = "success"), @ApiResponse(code = 400, message = "bad request", response = ApiError.class),
        @ApiResponse(code = 404, message = "not found", response = ApiError.class),
        @ApiResponse(code = 500, message = "error", response = ApiError.class) })
@BodyParser.Of(BodyParser.Raw.class)
public Result updatePurchaseOrderLineShipmentStatusType(
        @ApiParam(value = "A purchase order line shipment status type id", required = true) @PathParam("id") Long id) {
    try {

        PurchaseOrderLineShipmentStatusType purchaseOrderLineShipmentStatusType = PurchaseOrderDAO.getPurchaseOrderLineShipmentStatutsTypeById(id);
        // check if purchase order line shipment status type exist
        if (purchaseOrderLineShipmentStatusType == null) {
            return getJsonErrorResponse(new ApiError(404, "The purchase order line shipment status type with the specified id is not found"));
        }

        // Json to object
        JsonNode json = getRequestBodyAsJsonNode(request());

        // fill the play form
        Form<PurchaseOrderLineShipmentStatusTypeRequest> purchaseOrderLineShipmentStatusTypeRequestForm = purchaseOrderLineShipmentStatusTypeRequestFormTemplate
                .bind(json);

        // if errors
        if (purchaseOrderLineShipmentStatusTypeRequestForm.hasErrors()) {
            // get errors
            Map<String, List<ValidationError>> allErrors = purchaseOrderLineShipmentStatusTypeRequestForm.errors();
            // get errors to String Format
            String errorMsg = ApiError.getValidationErrorsMessage(getMessagesPlugin(), allErrors);
            return getJsonErrorResponse(new ApiError(404, errorMsg));
        }

        // Validation Form
        PurchaseOrderLineShipmentStatusTypeRequest purchaseOrderLineShipmentStatusTypeRequest = purchaseOrderLineShipmentStatusTypeRequestForm.get();

        // Save purchase order line shipment status type
        purchaseOrderLineShipmentStatusType.refId = purchaseOrderLineShipmentStatusTypeRequest.refId;
        purchaseOrderLineShipmentStatusType.name = purchaseOrderLineShipmentStatusTypeRequest.name;
        purchaseOrderLineShipmentStatusType.description = purchaseOrderLineShipmentStatusTypeRequest.description;
        purchaseOrderLineShipmentStatusType.isAmountExpanded = purchaseOrderLineShipmentStatusTypeRequest.isAmountExpanded;
        purchaseOrderLineShipmentStatusType.save();

        // json success
        return getJsonSuccessResponse(purchaseOrderLineShipmentStatusType);

    } catch (Exception e) {
        return getJsonErrorResponse(new ApiError(500, "Unexpected error", e));
    }
}
 
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:63,代码来源:PurchaseOrderLineShipmentStatusTypeApiController.java

示例12: udpatePortfolioEntryEventType

import play.mvc.BodyParser; //导入方法依赖的package包/类
/**
 * Update a portoflio entry event type.
 * 
 * WARNING: If an optional attribute is not given, then its current value
 * will be settled to null.
 * 
 * @param id
 *            the PE event type id
 * 
 * @return the JSON object of the corresponding PE event type.
 */
@ApiAuthentication(additionalCheck = ApiAuthenticationBizdockCheck.class)
@ApiOperation(value = "Update the specified Portfolio Entry Event Type, default for empty fields : null", notes = "Update a Portfolio Entry Event Type", response = PortfolioEntryEventTypeRequest.class, httpMethod = "PUT")
@ApiImplicitParams({
        @ApiImplicitParam(name = "body", value = "A input Portfolio Entry Event Type object", required = true, dataType = "PortfolioEntryEventTypeRequest", paramType = "body") })
@ApiResponses(value = { @ApiResponse(code = 200, message = "success"), @ApiResponse(code = 400, message = "bad request", response = ApiError.class),
        @ApiResponse(code = 404, message = "not found", response = ApiError.class),
        @ApiResponse(code = 500, message = "error", response = ApiError.class) })
@BodyParser.Of(BodyParser.Raw.class)
public Result udpatePortfolioEntryEventType(@ApiParam(value = "A PE event type id", required = true) @PathParam("id") Long id) {
    try {

        PortfolioEntryEventType peEventType = PortfolioEntryEventDao.getPEEventTypeById(id);
        if (peEventType == null) {
            return getJsonErrorResponse(new ApiError(404, "The PE Event Type with the specified id is not found"));
        }

        // Json to object
        JsonNode json = getRequestBodyAsJsonNode(request());

        // fill the play form
        Form<PortfolioEntryEventTypeRequest> portfolioEntryEventTypeRequestForm = portfolioEntryEventTypeRequestFormTemplate.bind(json);

        // if errors
        if (portfolioEntryEventTypeRequestForm.hasErrors()) {
            // get errors
            Map<String, List<ValidationError>> allErrors = portfolioEntryEventTypeRequestForm.errors();
            // get errors to String Format
            String errorMsg = ApiError.getValidationErrorsMessage(getMessagesPlugin(), allErrors);
            return getJsonErrorResponse(new ApiError(404, errorMsg));
        }

        // Validation Form
        PortfolioEntryEventTypeRequest portfolioEntryEventTypeRequest = portfolioEntryEventTypeRequestForm.get();

        // Save
        // fill to match with DB
        peEventType.name = portfolioEntryEventTypeRequest.name;
        peEventType.bootstrapGlyphicon = portfolioEntryEventTypeRequest.bootstrapGlyphicon;
        peEventType.selectable = portfolioEntryEventTypeRequest.selectable;

        peEventType.save();

        // json success
        return getJsonSuccessResponse(peEventType);

    } catch (Exception e) {
        return getJsonErrorResponse(new ApiError(500, "Unexpected error", e));
    }
}
 
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:61,代码来源:PortfolioEntryEventTypeApiController.java

示例13: createOrgUnit

import play.mvc.BodyParser; //导入方法依赖的package包/类
/**
 * Create an org unit.
 */
@ApiAuthentication(additionalCheck = ApiAuthenticationBizdockCheck.class)
@ApiOperation(value = "Create an OrgUnit", notes = "Create an OrgUnit", response = OrgUnitRequest.class, httpMethod = "POST")
@ApiImplicitParams({ @ApiImplicitParam(name = "body", value = "An OrgUnit", required = true, dataType = "OrgUnitRequest", paramType = "body") })
@ApiResponses(value = { @ApiResponse(code = 201, message = "success"), @ApiResponse(code = 400, message = "bad request", response = ApiError.class),
        @ApiResponse(code = 500, message = "error", response = ApiError.class) })
@BodyParser.Of(BodyParser.Raw.class)
public Result createOrgUnit() {
    try {

        // Json to object
        JsonNode json = getRequestBodyAsJsonNode(request());

        // fill the play form
        Form<OrgUnitRequest> orgUnitRequestForm = orgUnitRequestFormTemplate.bind(json);

        // if errors
        if (orgUnitRequestForm.hasErrors()) {
            // get errors
            Map<String, List<ValidationError>> allErrors = orgUnitRequestForm.errors();
            // get errors to String Format
            String errorMsg = ApiError.getValidationErrorsMessage(getMessagesPlugin(), allErrors);
            return getJsonErrorResponse(new ApiError(400, errorMsg));
        }

        // Validation Form
        OrgUnitRequest orgUnitRequest = orgUnitRequestForm.get();

        // fill to match with DB
        OrgUnit orgUnit = new OrgUnit();
        orgUnit.refId = orgUnitRequest.refId;
        orgUnit.name = orgUnitRequest.name;
        orgUnit.isActive = orgUnitRequest.isActive;
        orgUnit.canSponsor = orgUnitRequest.canSponsor;
        orgUnit.canDeliver = orgUnitRequest.canDeliver;
        orgUnit.orgUnitType = OrgUnitDao.getOrgUnitTypeById(orgUnitRequest.orgUnitTypeId);
        orgUnit.manager = ActorDao.getActorById(orgUnitRequest.managerId);
        orgUnit.parent = OrgUnitDao.getOrgUnitById(orgUnitRequest.parentId);

        // Save OrgUnit
        orgUnit.save();

        // return json success
        return getJsonSuccessCreatedResponse(orgUnit);

    } catch (Exception e) {
        return getJsonErrorResponse(new ApiError(500, "Unexpected error", e));
    }
}
 
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:52,代码来源:OrgUnitApiController.java

示例14: createUser

import play.mvc.BodyParser; //导入方法依赖的package包/类
/**
 * Create a User.
 */
@ApiAuthentication(additionalCheck = ApiAuthenticationBizdockCheck.class)
@ApiOperation(value = "Create a User", notes = "Create a User", response = UserRequestPost.class, httpMethod = "POST")
@ApiImplicitParams({ @ApiImplicitParam(name = "body", value = "A User", required = true, dataType = "UserRequestPost", paramType = "body") })
@ApiResponses(value = { @ApiResponse(code = 201, message = "success"), @ApiResponse(code = 400, message = "bad request", response = ApiError.class),
        @ApiResponse(code = 404, message = "not found", response = ApiError.class),
        @ApiResponse(code = 500, message = "error", response = ApiError.class) })
@BodyParser.Of(BodyParser.Raw.class)
public Result createUser() {
    try {
        // Json to object
        JsonNode json = getRequestBodyAsJsonNode(request());

        // fill the play form
        Form<UserRequestPost> userRequestForm = userRequestPostFormTemplate.bind(json);

        // if errors
        if (userRequestForm.hasErrors()) {
            // get errors
            Map<String, List<ValidationError>> allErrors = userRequestForm.errors();
            // get errors to String Format
            String errorMsg = ApiError.getValidationErrorsMessage(getMessagesPlugin(), allErrors);
            return getJsonErrorResponse(new ApiError(400, errorMsg));
        }

        // Validation Form
        UserRequestPost userRequestPost = userRequestForm.get();

        // get SystemLevelRoleTypesNames
        List<String> roleTypeNames = new ArrayList<String>();
        if (userRequestPost.systemLevelRoleTypesIds != null) {
            for (Long roleId : userRequestPost.systemLevelRoleTypesIds) {
                SystemLevelRoleType roleType = SystemLevelRoleType.getActiveRoleFromId(roleId);
                if (roleType == null) {
                    return getJsonErrorResponse(new ApiError(404, "One of the role type with the specified ids is not found"));
                } else {
                    roleTypeNames.add(roleType.name);
                }
            }
        } else {
            return getJsonErrorResponse(new ApiError(404, "You should have at least one role type"));
        }

        // fill to match with DB
        accountManager.createNewUserAccount(userRequestPost.uid, IUserAccount.AccountType.valueOf(userRequestPost.accountType), userRequestPost.firstName,
                userRequestPost.lastName, userRequestPost.mail, roleTypeNames);

        if (userRequestPost.preferredLanguage != null && userRequestPost.preferredLanguage.length() > 0) {
            if (messages.getValidLanguageMap().get(userRequestPost.preferredLanguage) == null) {
                return getJsonErrorResponse(new ApiError(500, "The only available language are : " + messages.getValidLanguageMap().keySet().toString()));
            }
            accountManager.updatePreferredLanguage(userRequestPost.uid, userRequestPost.preferredLanguage);
        }
        if (userRequestPost.password != null && userRequestPost.password.length() > 0) {
            accountManager.updatePassword(userRequestPost.uid, userRequestPost.password);
        }

        UserListRequest userListRequest = new UserListRequest(accountManager.getUserAccountFromUid(userRequestPost.uid));
        // json success
        return getJsonSuccessResponse(userListRequest);
    } catch (

    Exception e)

    {
        return getJsonErrorResponse(new ApiError(500, "Unexpected error", e));
    }

}
 
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:72,代码来源:UserApiController.java

示例15: udpatePortfolioEntryReportStatusType

import play.mvc.BodyParser; //导入方法依赖的package包/类
/**
 * Update a portoflio entry Report Status type.
 * 
 * WARNING: If an optional attribute is not given, then its current value
 * will be settled to null.
 * 
 * @param id
 *            the PE Report Status type id
 * 
 * @return the JSON object of the corresponding PE Report Status type.
 */
@ApiAuthentication(additionalCheck = ApiAuthenticationBizdockCheck.class)
@ApiOperation(value = "Update the specified Portfolio Entry Report Status Type, default for empty fields : null", notes = "Update a Portfolio Entry Report Status Type", response = PortfolioEntryReportStatusTypeRequest.class, httpMethod = "PUT")
@ApiImplicitParams({
        @ApiImplicitParam(name = "body", value = "A input Portfolio Entry Report Status Type object", required = true, dataType = "PortfolioEntryReportStatusTypeRequest", paramType = "body") })
@ApiResponses(value = { @ApiResponse(code = 200, message = "success"), @ApiResponse(code = 400, message = "bad request", response = ApiError.class),
        @ApiResponse(code = 404, message = "not found", response = ApiError.class),
        @ApiResponse(code = 500, message = "error", response = ApiError.class) })
@BodyParser.Of(BodyParser.Raw.class)
public Result udpatePortfolioEntryReportStatusType(@ApiParam(value = "A PE Report Status type id", required = true) @PathParam("id") Long id) {
    try {

        PortfolioEntryReportStatusType portfolioEntryReportStatusType = PortfolioEntryReportDao.getPEReportStatusTypeById(id);
        if (portfolioEntryReportStatusType == null) {
            return getJsonErrorResponse(new ApiError(404, "The PE Report Status Type with the specified id is not found"));
        }

        // Json to object
        JsonNode json = getRequestBodyAsJsonNode(request());

        // fill the play form
        Form<PortfolioEntryReportStatusTypeRequest> portfolioEntryReportStatusTypeRequestForm = portfolioEntryReportStatusTypeRequestFormTemplate
                .bind(json);

        // if errors
        if (portfolioEntryReportStatusTypeRequestForm.hasErrors()) {
            // get errors
            Map<String, List<ValidationError>> allErrors = portfolioEntryReportStatusTypeRequestForm.errors();
            // get errors to String Format
            String errorMsg = ApiError.getValidationErrorsMessage(getMessagesPlugin(), allErrors);
            return getJsonErrorResponse(new ApiError(404, errorMsg));
        }

        // Validation Form
        PortfolioEntryReportStatusTypeRequest portfolioEntryReportStatusTypeRequest = portfolioEntryReportStatusTypeRequestForm.get();

        // Save
        // fill to match with DB
        portfolioEntryReportStatusType.name = portfolioEntryReportStatusTypeRequest.name;
        portfolioEntryReportStatusType.description = portfolioEntryReportStatusTypeRequest.description;
        portfolioEntryReportStatusType.selectable = portfolioEntryReportStatusTypeRequest.selectable;
        portfolioEntryReportStatusType.cssClass = portfolioEntryReportStatusTypeRequest.cssClass;

        portfolioEntryReportStatusType.save();

        // json success
        return getJsonSuccessResponse(portfolioEntryReportStatusType);

    } catch (Exception e) {
        return getJsonErrorResponse(new ApiError(500, "Unexpected error", e));
    }
}
 
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:63,代码来源:PortfolioEntryReportStatusTypeApiController.java


注:本文中的play.mvc.BodyParser.Raw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。