All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.anotheria.anosite.gen.aswebdata.action.MultiOpAttributesSubattributesAction Maven / Gradle / Ivy

There is a newer version: 4.1.2
Show newest version
/**
 ********************************************************************************
 *** MultiOpAttributesSubattributesAction.java                                ***
 *** generated by AnoSiteGenerator (ASG), Version: 3.2.2                      ***
 *** Copyright (C) 2005 - 2023 Anotheria.net, www.anotheria.net               ***
 *** All Rights Reserved.                                                     ***
 ********************************************************************************
 *** Don't edit this code, if you aren't sure                                 ***
 *** that you do exactly know what you are doing!                             ***
 *** It's better to invest time in the generator, as into the generated code. ***
 ********************************************************************************
 */

package net.anotheria.anosite.gen.aswebdata.action;

import java.util.List;
import java.util.ArrayList;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import net.anotheria.maf.action.ActionCommand;
import net.anotheria.maf.action.ActionMapping;
import net.anotheria.anosite.gen.aswebdata.data.AttributeFactory;
import net.anotheria.anosite.gen.aswebdata.data.Attribute;
import net.anotheria.anosite.gen.aswebdata.bean.SubattributesElementFB;
import net.anotheria.asg.util.bean.PopulateUtility;
import net.anotheria.anosite.gen.aswebdata.bean.SubattributesQuickAddFB;
import net.anotheria.anosite.gen.aswebdata.data.AttributeSortType;
import net.anotheria.webutils.bean.LabelValueBean;
import net.anotheria.anodoc.data.NoSuchDocumentException;
import net.anotheria.util.StringUtils;
import net.anotheria.asg.exception.ASGRuntimeException;

public class MultiOpAttributesSubattributesAction extends BaseAttributeAction{

	// Generated by: class net.anotheria.asg.generator.view.action.ModuleActionsGenerator.generateContainerMultiOpAction

	public ActionCommand anoDocExecute(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
		String path = stripPath(mapping.getPath());
		if (path.equals("aswebdataAttributeSubattributesShow"))
			return aswebdataAttributeSubattributesShow(mapping, req, res);
		if (path.equals("aswebdataAttributeSubattributesAdd"))
			return aswebdataAttributeSubattributesAdd(mapping, req, res);
		if (path.equals("aswebdataAttributeSubattributesDelete"))
			return aswebdataAttributeSubattributesDelete(mapping, req, res);
		if (path.equals("aswebdataAttributeSubattributesMove"))
			return aswebdataAttributeSubattributesMove(mapping, req, res);
		if (path.equals("aswebdataAttributeSubattributesQuickAdd"))
			return aswebdataAttributeSubattributesQuickAdd(mapping, req, res);
		throw new IllegalArgumentException("Unknown path: "+path);
	}

	// Generated by: class net.anotheria.asg.generator.view.action.ModuleActionsGenerator.generateListShowActionMethod

	public ActionCommand aswebdataAttributeSubattributesShow(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
		String id = getStringParameter(req, "ownerId");
		Attribute attribute = getASWebDataService().getAttribute(id);
		addBeanToRequest(req, "ownerId", id);
		checkAttributes(attribute, req);

		SubattributesElementFB form = new SubattributesElementFB() ;
		form.setPosition(-1);
		form.setOwnerId(attribute.getId());
		addBeanToRequest(req, "aswebdataAttributeSubattributesElementForm", form);

		SubattributesQuickAddFB quickAddForm = new SubattributesQuickAddFB() ;
		quickAddForm.setOwnerId(attribute.getId());
		addBeanToRequest(req, "aswebdataAttributeSubattributesQuickAddForm", quickAddForm);


		//link type to Attribute
		List attributes = getASWebDataService().getAttributes(new AttributeSortType(AttributeSortType.SORT_BY_NAME));
		List attributesValues = new ArrayList(attributes.size());
		for (int i=0; i beans = new ArrayList(size);
		for (int i=0; i targetList = attribute.getSubattributes();
		String toSwap = targetList.remove(position);
		targetList.add(0, toSwap);
		attribute.setSubattributes(targetList);
		getASWebDataService().updateAttribute(attribute);
	}

	private void moveDown(Attribute attribute, int position) throws ASGRuntimeException {
		if (position targetList = attribute.getSubattributes();
		String toSwap = targetList.remove(position);
		targetList.add(toSwap);
		attribute.setSubattributes(targetList);
		getASWebDataService().updateAttribute(attribute);
	}

	// Generated by: class net.anotheria.asg.generator.view.action.ModuleActionsGenerator.generateListAddRowActionMethod

	public ActionCommand aswebdataAttributeSubattributesAdd(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
		SubattributesElementFB form = new SubattributesElementFB();
		PopulateUtility.populate(form, req);
		String id = form.getOwnerId();
		Attribute attribute;
		attribute = getASWebDataService().getAttribute(id);
		canUpdateAttributes(attribute, req);
		checkAttributes(attribute, req);
		attribute.addSubattributesElement(form.getType());
		getASWebDataService().updateAttribute(attribute);
		return aswebdataAttributeSubattributesShow(mapping, req, res);
	}

	// Generated by: class net.anotheria.asg.generator.view.action.ModuleActionsGenerator.generateListQuickAddActionMethod

	public ActionCommand aswebdataAttributeSubattributesQuickAdd(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
		SubattributesQuickAddFB form = new SubattributesQuickAddFB();
		PopulateUtility.populate(form, req);
		String id = form.getOwnerId();
		Attribute attribute;
		attribute = getASWebDataService().getAttribute(id);
		canUpdateAttributes(attribute, req);
		checkAttributes(attribute, req);
		String paramIdsToAdd = form.getQuickAddIds();

		String idParameters[] = StringUtils.tokenize(paramIdsToAdd, ',');
		for (String anIdParam : idParameters){
			String ids[] = StringUtils.tokenize(anIdParam, '-');
			for (int i=Integer.parseInt(ids[0]); i<=Integer.parseInt(ids[ids.length-1]); i++){
				attribute.addSubattributesElement(""+i);
			}
		}
		getASWebDataService().updateAttribute(attribute);
		return aswebdataAttributeSubattributesShow(mapping, req, res);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy