Best Cerberus-source code snippet using org.cerberus.servlet.crud.countryenvironment.UpdateAppService
Source:UpdateAppService.java
...61import java.util.Map;62/**63 * @author cte64 */65@WebServlet(name = "UpdateAppService", urlPatterns = {"/UpdateAppService"})66public class UpdateAppService extends HttpServlet {67 private static final Logger LOG = LogManager.getLogger(UpdateAppService.class);68 private IAppServiceService appServiceService;69 private IAppServiceHeaderService appServiceHeaderService;70 private IAppServiceContentService appServiceContentService;71 private ILogEventService logEventService;72 private IFactoryAppServiceContent appServiceContentFactory;73 private IFactoryAppServiceHeader appServiceHeaderFactory;74 /**75 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>76 * methods.77 *78 * @param request servlet request79 * @param response servlet response80 * @throws ServletException if a servlet-specific error occurs81 * @throws IOException if an I/O error occurs82 */83 final void processRequest(final HttpServletRequest request, final HttpServletResponse response)84 throws ServletException, IOException, CerberusException, JSONException {85 JSONObject jsonResponse = new JSONObject();86 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());87 Answer ans = new Answer();88 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);89 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));90 ans.setResultMessage(msg);91 response.setContentType("text/html;charset=UTF-8");92 String charset = request.getCharacterEncoding() == null ? "UTF-8" : request.getCharacterEncoding();93 Map<String, String> fileData = new HashMap<>();94 FileItem file = null;95 FileItemFactory factory = new DiskFileItemFactory();96 ServletFileUpload upload = new ServletFileUpload(factory);97 try {98 List<FileItem> fields = upload.parseRequest(request);99 Iterator<FileItem> it = fields.iterator();100 if (!it.hasNext()) {101 return;102 }103 while (it.hasNext()) {104 FileItem fileItem = it.next();105 boolean isFormField = fileItem.isFormField();106 if (isFormField) {107 fileData.put(fileItem.getFieldName(), fileItem.getString("UTF-8"));108 } else {109 file = fileItem;110 }111 }112 } catch (FileUploadException e) {113 e.printStackTrace();114 }115 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them116 // Parameter that needs to be secured --> We SECURE+DECODE them117 String service = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(fileData.get("service"), null, charset);118 String originalService = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(fileData.get("originalService"), null, charset);119 String group = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(fileData.get("group"), null, charset);120 String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(fileData.get("description"), null, charset);121 String attachementurl = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(fileData.get("attachementurl"), null, charset);122 String operation = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(fileData.get("operation"), null, charset);123 String application = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(fileData.get("application"), null, charset);124 String type = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(fileData.get("type"), null, charset);125 String method = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(fileData.get("method"), "", charset);126 // Parameter that we cannot secure as we need the html --> We DECODE them127 String servicePath = ParameterParserUtil.parseStringParamAndDecode(fileData.get("servicePath"), null, charset);128 boolean isFollowRedir = ParameterParserUtil.parseBooleanParam(fileData.get("isFollowRedir"), true);129 String serviceRequest = ParameterParserUtil.parseStringParamAndDecode(fileData.get("srvRequest"), null, charset);130 String kafkaTopic = ParameterParserUtil.parseStringParamAndDecode(fileData.get("kafkaTopic"), "", charset);131 boolean isAvroEnable = ParameterParserUtil.parseBooleanParam(fileData.get("isAvroEnable"), false);132 String schemaRegistryUrl = ParameterParserUtil.parseStringParamAndDecode(fileData.get("schemaRegistryUrl"), null, charset);133 String parentContentService = ParameterParserUtil.parseStringParamAndDecode(fileData.get("parentContentService"), "", charset);134 String kafkaKey = ParameterParserUtil.parseStringParamAndDecode(fileData.get("kafkaKey"), "", charset);135 String kafkaFilterPath = ParameterParserUtil.parseStringParamAndDecode(fileData.get("kafkaFilterPath"), "", charset);136 String kafkaFilterValue = ParameterParserUtil.parseStringParamAndDecode(fileData.get("kafkaFilterValue"), "", charset);137 String kafkaFilterHeaderPath = ParameterParserUtil.parseStringParamAndDecode(fileData.get("kafkaFilterHeaderPath"), "", charset);138 String kafkaFilterHeaderValue = ParameterParserUtil.parseStringParamAndDecode(fileData.get("kafkaFilterHeaderValue"), "", charset);139 String fileName = null;140 if (file != null) {141 fileName = file.getName();142 }143 // Prepare the final answer.144 MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);145 Answer finalAnswer = new Answer(msg1);146 /**147 * Checking all constrains before calling the services.148 */149 if (StringUtil.isNullOrEmpty(originalService)) {150 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);151 msg.setDescription(msg.getDescription().replace("%ITEM%", "AppService")152 .replace("%OPERATION%", "Update")153 .replace("%REASON%", "AppService ID (service) is missing."));154 finalAnswer.setResultMessage(msg);155 } else {156 /**157 * All data seems cleans so we can call the services.158 */159 appServiceService = appContext.getBean(IAppServiceService.class);160 appServiceHeaderService = appContext.getBean(IAppServiceHeaderService.class);161 appServiceContentService = appContext.getBean(IAppServiceContentService.class);162 appServiceContentFactory = appContext.getBean(IFactoryAppServiceContent.class);163 appServiceHeaderFactory = appContext.getBean(IFactoryAppServiceHeader.class);164 AnswerItem resp = appServiceService.readByKey(originalService);165 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {166 /**167 * Object could not be found. We stop here and report the error.168 */169 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, resp);170 } else {171 /**172 * The service was able to perform the query and confirm the173 * object exist, then we can update it.174 */175 AppService appService = (AppService) resp.getItem();176 if (file != null) {177 ans = appServiceService.uploadFile(appService.getService(), file);178 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {179 appService.setFileName(file.getName());180 }181 }182 appService.setService(service);183 appService.setGroup(group);184 appService.setAttachementURL(attachementurl);185 appService.setDescription(description);186 appService.setServiceRequest(serviceRequest);187 appService.setOperation(operation);188 appService.setType(type);189 appService.setApplication(application);190 appService.setMethod(method);191 appService.setServicePath(servicePath);192 appService.setUsrModif(request.getRemoteUser());193 appService.setKafkaKey(kafkaKey);194 appService.setKafkaTopic(kafkaTopic);195 appService.setKafkaFilterPath(kafkaFilterPath);196 appService.setKafkaFilterValue(kafkaFilterValue);197 appService.setKafkaFilterHeaderPath(kafkaFilterHeaderPath);198 appService.setKafkaFilterHeaderValue(kafkaFilterHeaderValue);199 appService.setFollowRedir(isFollowRedir);200 appService.setAvroEnable(isAvroEnable);201 appService.setSchemaRegistryURL(schemaRegistryUrl);202 appService.setParentContentService(parentContentService);203 ans = appServiceService.update(originalService, appService);204 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, ans);205 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {206 /**207 * Update was successful. Adding Log entry.208 */209 logEventService = appContext.getBean(ILogEventService.class);210 logEventService.createForPrivateCalls("/UpdateAppService", "UPDATE", "Updated AppService : ['" + originalService + "']", request);211 }212 // Update content213 if (fileData.get("contentList") != null) {214 JSONArray objContentArray = new JSONArray(fileData.get("contentList"));215 List<AppServiceContent> contentList = new ArrayList<>();216 contentList = getContentListFromRequest(request, appContext, service, objContentArray);217 // Update the Database with the new list.218 ans = appServiceContentService.compareListAndUpdateInsertDeleteElements(service, contentList);219 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, ans);220 }221 // Update header222 if (fileData.get("headerList") != null) {223 JSONArray objHeaderArray = new JSONArray(fileData.get("headerList"));224 List<AppServiceHeader> headerList = new ArrayList<>();...
UpdateAppService
Using AI Code Generation
1UpdateAppService updateAppService = appContext.getBean(UpdateAppService.class);2updateAppService.execute(request);3UpdateAppService updateAppService = appContext.getBean(UpdateAppService.class);4updateAppService.execute(request);5package org.cerberus.servlet.crud.countryenvironment;6import org.cerberus.crud.entity.Application;7import org.cerberus.crud.factory.IFactoryApplication;8import org.cerberus.crud.service.IApplicationService;9import org.cerberus.engine.entity.MessageEvent;10import org.cerberus.engine.entity.MessageEventEnum;11import org.cerberus.servlet.crud.CreateService;12import org.cerberus.util.answer.AnswerItem;13import org.springframework.beans.factory.annotation.Autowired;14import org.springframework.stereotype.Service;15import org.springframework.web.context.support.SpringBeanAutowiringSupport;16import javax.servlet.http.HttpServletRequest;17public class CreateAppService extends SpringBeanAutowiringSupport implements CreateService {18 private IFactoryApplication factoryApplication;19 private IApplicationService applicationService;20 public AnswerItem create(HttpServletRequest request) {21 String application = request.getParameter("Application");22 String system = request.getParameter("System");23 String description = request.getParameter("Description");24 String type = request.getParameter("Type");25 String active = request.getParameter("Active");26 String sort = request.getParameter("Sort");27 String usrCreated = request.getParameter("UsrCreated");28 String usrModif = request.getParameter("UsrModif");29 String appSystem = request.getParameter("AppSystem");30 String applicationSystem = request.getParameter("ApplicationSystem");31 String appSystemDescription = request.getParameter("AppSystemDescription");32 String appSystemActive = request.getParameter("AppSystemActive");33 String appSystemSort = request.getParameter("AppSystemSort");34 String appSystemUsrCreated = request.getParameter("AppSystemUsrCreated");35 String appSystemUsrModif = request.getParameter("AppSystemUsrModif");36 String applicationSystemDescription = request.getParameter("ApplicationSystemDescription");37 String applicationSystemActive = request.getParameter("ApplicationSystemActive");38 String applicationSystemSort = request.getParameter("ApplicationSystemSort");39 String applicationSystemUsrCreated = request.getParameter("ApplicationSystemUsrCreated");
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!