}
}
if (o != null) {
//Start image specific code
if (o instanceof FormBuilderItemImage || o instanceof FormBuilderItemDownload) {
FormBuilderItemBase object = (FormBuilderItemBase) o;
for (FormBuilderItemBase tmpItem : formBuilder.getForm().getItems()) {
if (tmpItem.getId().equals(object.getId())) {
cachedObjects.put(tmpItem.getId(), tmpItem);
}
}
}
//End image specific code
FormBuilderItemBase itemBase = (FormBuilderItemBase) o;
itemBase.setPosition(itemBase.getPosition() + positionOffset);
itemBase.initConstraintsFromConstraintsString(formBuilder.getWorkflowStates(), formBuilder.getConstraintClients());
list.add((FormBuilderItemBase) o);
//Start format area specific code
if (o instanceof FormBuilderItemFormatArea || o instanceof FormBuilderItemConstraint) {
FormBuilderItemBase area = (FormBuilderItemBase) o;
if (area.getProperties().getBrother() == null) {
HashMap<String, String> areasMap = new HashMap<>();
HashMap<String, String> constraintsMap = new HashMap<>();
for (FormBuilderItemBase tmpItem : formBuilder.getForm().getItems()) {
if (tmpItem instanceof FormBuilderItemFormatArea
&& !areasMap.containsKey(tmpItem.getProperties().getFormatareauuid())) {
areasMap.put(tmpItem.getProperties().getFormatareauuid(), null);
}
if (tmpItem instanceof FormBuilderItemConstraint
&& !areasMap.containsKey(tmpItem.getProperties().getFormatareauuid())) {
constraintsMap.put(tmpItem.getProperties().getFormatareauuid(), null);
}
}
int areas = 1 + areasMap.size();
int constrains = 1 + constraintsMap.size();
FormBuilderItemBase brother = null;
if (o instanceof FormBuilderItemFormatArea) {
brother = new FormBuilderItemFormatArea();
} else {
brother = new FormBuilderItemConstraint();
}
brother.getProperties().setBrother(area.getId());
brother.setBrother(area);
brother.setPosition(area.getPosition() + 1);
area.getProperties().setBrother(brother.getId());
area.setBrother(brother);
list.add(brother);
String formatAreaUuid = UUID.randomUUID().toString();
area.getProperties().setFormatareauuid(formatAreaUuid);
brother.getProperties().setFormatareauuid(formatAreaUuid);
if (o instanceof FormBuilderItemFormatArea) {
area.getProperties().setValues(area.getProperties().getValues() + " " + areas);
brother.getProperties().setValues(brother.getProperties().getValues() + " " + areas);
} else {
area.getProperties().setValues(area.getProperties().getValues() + " " + constrains);
brother.getProperties().setValues(brother.getProperties().getValues() + " " + constrains);
}
positionOffset++;
}
if (o instanceof FormBuilderItemFormatArea) {
if (activeFormatArea == null) {
activeFormatArea = area.getProperties().getFormatareauuid();
} else if (activeFormatArea.equals(area.getProperties().getFormatareauuid())) {
activeFormatArea = null;
} else {
throw new RuntimeException(Messages.getStringJSF("formatarea.error"));
}
} else {
if (activeConstraint == null) {
activeConstraint = area.getProperties().getFormatareauuid();
} else if (activeConstraint.equals(area.getProperties().getFormatareauuid())) {
activeConstraint = null;
} else {
throw new RuntimeException(Messages.getStringJSF("constraint.error"));
}
}
}
//End format area specific code
}
}
}
}
if (!list.isEmpty()) {
formBuilder.getForm().getItems().clear();
formBuilder.getForm().addItems(list);
}
//Start image specific code
if (!cachedObjects.isEmpty()) {
for (FormBuilderItemBase tmpItem : formBuilder.getForm().getItems()) {
if ((tmpItem instanceof FormBuilderItemImage || tmpItem instanceof FormBuilderItemDownload)
&& cachedObjects.containsKey(tmpItem.getId())) {
tmpItem.getProperties().setFile(cachedObjects.get(tmpItem.getId()).getProperties().getFile());
}
}
}
HttpServletRequest request = (HttpServletRequest) ctx.getExternalContext().getRequest();
MultipartRequest multiRequest = new MultipartRequest(request);
for (String key : multiRequest.getFiles().keySet()) {
for (FormBuilderItemBase item : formBuilder.getForm().getItems()) {
if (key.contains(item.getId())) {
item.getProperties().setFile(multiRequest.getFiles().get(key));
}
}
}
//End image specific code
break;
case "edit":
try {
FormBuilderItemUpdateHolder updateHolder = mapper.readValue(formContentString, FormBuilderItemUpdateHolder.class);
List<FormBuilderItemBase> items = formBuilder.getForm().getItems();
for (FormBuilderItemBase item : items) {
if (item.getId().equals(updateHolder.getItemId())) {
FormBuilderItemFactory.updateFormBuilderItem(item, updateHolder.getUpdates());
if (item instanceof FormBuilderItemFormatArea || item instanceof FormBuilderItemConstraint) {
for (FormBuilderItemBase item2 : items) {
if (item2.getProperties().getBrother() != null
&& (item2 instanceof FormBuilderItemFormatArea || item2 instanceof FormBuilderItemConstraint)
&& item2.getProperties().getBrother().equals(item.getId())) {
Iterator<FormBuilderItemUpdate> updateIter = updateHolder.getUpdates().iterator();
while (updateIter.hasNext()) {
FormBuilderItemUpdate update = updateIter.next();
if (update.getMethod().equals("brother")) {
updateIter.remove();
}
}
FormBuilderItemFactory.updateFormBuilderItem(item2, updateHolder.getUpdates());
}
}
}
}
}
} catch (IOException ex) {
Logger.getLogger(FormBuilderInternalRenderer.class.getName()).log(Level.SEVERE, null, ex);
}
break;
case "delete":
List<FormBuilderItemBase> items = formBuilder.getForm().getItems();
Iterator<FormBuilderItemBase> itemIter = items.iterator();
String brotherToDelete = null;
while (itemIter.hasNext()) {
FormBuilderItemBase item = itemIter.next();
if (item.getId().equals(formContentString)) {
if (item instanceof FormBuilderItemFormatArea || item instanceof FormBuilderItemConstraint) {
brotherToDelete = item.getProperties().getBrother();
}
itemIter.remove();
break;
}
}
if (brotherToDelete != null) {
itemIter = items.iterator();
while (itemIter.hasNext()) {
FormBuilderItemBase item = itemIter.next();
if (item.getId().equals(brotherToDelete)) {
itemIter.remove();
break;
}
}
}