Skip to content

Commit

Permalink
Updated changes of issue #283 and improvements on issue #285
Browse files Browse the repository at this point in the history
  • Loading branch information
unaibrrgn committed Jun 23, 2023
1 parent 3fbc753 commit 02b690f
Showing 1 changed file with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,18 @@ public void createFileTemplate(RegItemclass regItemclass, EntityManager entityMa
if (checkIfFieldTypeIsParentReferenceOrString(regFieldUuid)) {
regFieldMappingListWithoutSomeFields.add(regFieldMapping);
}
/**
if(!regFieldUuid.equals(BaseConstants.KEY_FIELDTYPE_STATUS_UUID)){
regFieldMappingListWithoutSomeFields.add(regFieldMapping);
}
**/

}

response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=" + regItemclassChild.getLocalid() + ".csv");

try (ServletOutputStream output = response.getOutputStream()) {
try ( ServletOutputStream output = response.getOutputStream()) {
StringBuilder sb = generateCsvFileBuffer(regFieldMappingListWithoutSomeFields);

InputStream input = new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));
Expand Down Expand Up @@ -166,6 +172,8 @@ private static StringBuilder generateCsvFileBuffer(List<RegFieldmapping> regFiel
for (RegFieldmapping field : regFieldMappingListWithoutStatus) {
writer.append("|");

//Adds CollectionTheme field to the csv when there is a Theme field on the item
/**
if (field.getRegField().getRegFieldtype().getUuid().equals(BaseConstants.KEY_FIELDTYPE_RELATIONREFERENCE_UUID)) {
writer.append(field.getRegField().getLocalid());
writer.append("|");
Expand All @@ -174,6 +182,8 @@ private static StringBuilder generateCsvFileBuffer(List<RegFieldmapping> regFiel
} else {
writer.append(field.getRegField().getLocalid());
}
**/
writer.append(field.getRegField().getLocalid());
}

return writer;
Expand Down Expand Up @@ -209,6 +219,7 @@ public void processFile(HttpServletRequest request, RegItem regItem, RegUser reg
LOGGER.info("###");
LOGGER.info("### ANALIZE FILE ###");
HashMap<String, ArrayList<FieldsBulkImport>> itemsBulkImport = analyzeFile(headerListSplitted, additionLines, regItem);
checkRequired(additionLines, regItem);
LOGGER.info("### THE FILE HAS BEEN ANALIZED ###");
LOGGER.info("###");
LOGGER.info("### START STORING ITEMS ###");
Expand Down Expand Up @@ -262,6 +273,30 @@ public void processFile(HttpServletRequest request, RegItem regItem, RegUser reg
// Sending the mail
MailManager.sendMail(recipient, subject, body);
}

private boolean checkRequired(List<String> additionLines, RegItem regItem){
RegFieldmappingManager regFieldmappingManager = new RegFieldmappingManager(entityManager);
List<RegFieldmapping> regFieldMappingList = new ArrayList<>();
try{
RegItemclass regItemclassChild = getItemClassChildren(regItem);
regFieldMappingList = regFieldmappingManager.getAll(regItemclassChild);


for(int i = 0; i < additionLines.size();i++){
String[] addLineSplitted = additionLines.get(i).split("\\|", -1);
List<String> linesListSplitted = new ArrayList<>(Arrays.asList(addLineSplitted));
for(int j = 0; j < regFieldMappingList.size(); j++){
if(regFieldMappingList.get(j).getRequired()==true && linesListSplitted.get(i).equalsIgnoreCase("")){
System.out.println("Cascaste");
}
}
}
} catch(Exception e){
e.printStackTrace();
}

return false;
}

private String[] readFileFromServletFileUpload(HttpServletRequest request) throws IOException, FileUploadException {
List<FileItem> fl = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
Expand Down Expand Up @@ -943,9 +978,10 @@ private void storeRelarionReference(String fieldValue, RegField regField, RegIte
} else {
relationReferenceList.add(fieldValue);
}


int i = 0;
for (String valueOfTheField : relationReferenceList) {

try {
RegItemclass itemClassRelationReference = regField.getRegItemclassReference();
String relationreferenceuuid = "";
Expand Down Expand Up @@ -977,7 +1013,7 @@ private void storeRelarionReference(String fieldValue, RegField regField, RegIte

// create localization for red relation proposed
RegLocalizationproposed regLocalizationproposed = new RegLocalizationproposed();
regLocalizationproposed.setUuid(RegLocalizationproposedUuidHelper.getUuid(0, fieldLanguage, regItemproposed, regField));
regLocalizationproposed.setUuid(RegLocalizationproposedUuidHelper.getUuid(i, fieldLanguage, regItemproposed, regField));
regLocalizationproposed.setRegLanguagecode(fieldLanguage);
regLocalizationproposed.setRegItemproposed(regItemproposed);
regLocalizationproposed.setRegField(regField);
Expand Down Expand Up @@ -1007,6 +1043,7 @@ private void storeRelarionReference(String fieldValue, RegField regField, RegIte
.replace(SUBSTITUTE_LINE, String.valueOf(fieldsBulkImport.getLine()));
operationResult = operationResult + BR_HTML + relation_error;
}
i++;
}
}

Expand Down

0 comments on commit 02b690f

Please sign in to comment.