Here is my code:
private static final Logger log = LoggerFactory.getLogger(ImportTestCaseServlet.class);
@Autowired
TestCaseService testCaseService;
@Autowired
DeviceService deviceService;
@Autowired
UploadFileService uploadFileService;
@Autowired
ProjectService projectService;
@Autowired
private TesterPerformanceService testerPerformanceService;
@Autowired
JiraAuthenticationContext jiraAuthenticationContext;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final String deviceType = req.getParameter(DEVICE_TYPE);
final String importType = req.getParameter(IMPORT_DEVICE_TYPE);
resp.setContentType(CONTENT_TYPE);
resp.setCharacterEncoding(CHARACTER_ENCODING);
final Map<String, String> errors = new HashMap<>();
final Map<String, Object> data = new HashMap<>();
ApplicationUser user = jiraAuthenticationContext.getLoggedInUser();
long projectId = Long.parseLong(req.getParameter(PARAMETER_PROJECT_ID));
String role = testerPerformanceService.getRole(user, projectId);
final ProjectManager projectManager = ComponentAccessor.getProjectManager();
final Project project = projectManager.getProjectObj(Long.parseLong(req.getParameter(PARAMETER_PROJECT_ID)));
if (Objects.equals(role, PROJECT_ROLE_QC_LEAD) && Objects.equals(importType, IMPORT_TYPE_IMPORT_DEVICE)) {
errors.put(MESSAGE_ERROR_TEST_CASE_TYPE, DEVICE_PERMISSION);
}
if (StringUtils.equalsIgnoreCase(importType, IMPORT_TYPE_UPDATE_ASSIGNEE) && StringUtils.isBlank(deviceType)) {
errors.put(MESSAGE_ERROR_TEST_CASE_TYPE, TEST_CASE_TYPE_REQUIRED);
}
if (errors.size() > 0) {
resp.getWriter().write(new Gson().toJson(errors));
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
} else {
final ResultMessage resultMessage = deviceService.imports(req, resp);
if (resultMessage.getCode() == HttpServletResponse.SC_OK) {
data.put(Constants.LIST_FILE_UP_LOAD, uploadFileService.findAllByProjectId(project.getId(), null));
data.put(Constants.TOTAL_ROWS_IMPORT_SUCCESS, resultMessage.getTotalRowSuccess());
data.put(Constants.TOTAL_ROWS_IMPORT_ERROR, resultMessage.getTotalRowError());
data.put(Constants.TOTAL_ROWS, resultMessage.getTotalRows());
resp.getWriter().write(new Gson().toJson(data));
resp.setStatus(HttpServletResponse.SC_OK);
} else {
errors.put(MESSAGE_ERROR_SERVICE, resultMessage.getMessage());
resp.getWriter().write(new Gson().toJson(errors));
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
}
Please explain ,why return jiraAuthenticationContext.getLoggedInUser() null.
It could be the person who makes the request did not log in.
hi @Manh Tuan Do ,
Try this ,
ApplicationUser user=ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
Let me know if it works for you or not.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Manh Tuan Do ,
I guess above method is now deprecated. so can you please try this,
ApplicationUser user=ComponentAccessor.getJiraAuthenticationContext().getUser();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I use version 7.7.1, on my version getLoggedInUser () is supported, getUser has not been used anymore. although I tried both getUser () but it didn't work.
Thanks you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.