package modules.admin.DataMaintenance.actions;

import java.io.File;

import org.skyve.CORE;
import org.skyve.impl.backup.ExternalBackup;
import org.skyve.metadata.controller.ServerSideAction;
import org.skyve.metadata.controller.ServerSideActionResult;
import org.skyve.util.FileUtil;
import org.skyve.util.Util;
import org.skyve.web.WebContext;

import modules.admin.domain.DataMaintenance;

public class DeleteBackup implements ServerSideAction<DataMaintenance> {
	private static final long serialVersionUID = 5306067916641877356L;

	@Override
	public ServerSideActionResult<DataMaintenance> execute(DataMaintenance bean, WebContext webContext)
	throws Exception {
		String customerName = CORE.getUser().getCustomerName();
		
		// delete external backup if enabled
				if (ExternalBackup.areExternalBackupsEnabled()) {
					String backupName = bean.getSelectedBackupName();
					if (ExternalBackup.getInstance().exists(backupName)) {
						Util.LOGGER.info("Deleting backup " + backupName);
						ExternalBackup.getInstance().deleteBackup(bean.getSelectedBackupName());
						Util.LOGGER.info("Deleted backup " + backupName);
					} else {
						Util.LOGGER.info("Backup " + backupName + " no longer exists");
					}
				} else {
					// delete from local content
					File backup = new File(String.format("%sbackup_%s%s%s",
							Util.getContentDirectory(),
							customerName,
							File.separator,
							bean.getSelectedBackupName()));
					if (backup.exists()) {
						Util.LOGGER.info("Deleting backup " + backup.getAbsolutePath());
						FileUtil.delete(backup);
						Util.LOGGER.info("Deleted backup " + backup.getAbsolutePath());
					} else {
						Util.LOGGER.info("Backup " + backup.getAbsolutePath() + " no longer exists");
					}
				}

				// deselect the deleted backup
				bean.setSelectedBackupName(null);
				bean.setRefreshBackups(Boolean.TRUE);

		return new ServerSideActionResult<>(bean);
	}
}

@@ -761,18 +761,16 @@
 enabled%0A
-%09%09
 %09%09if (Ex
@@ -813,18 +813,16 @@
 ed()) %7B%0A
-%09%09
 %09%09%09Strin
@@ -865,26 +865,24 @@
 pName();%0A%09%09%09
-%09%09
 if (External
@@ -920,34 +920,32 @@
 kupName)) %7B%0A%09%09%09%09
-%09
-%09
 Util.LOGGER.info
@@ -979,18 +979,16 @@
 pName);%0A
-%09%09
 %09%09%09%09Exte
@@ -1056,26 +1056,24 @@
 ame());%0A%09%09%09%09
-%09
-%09
 Util.LOGGER.
@@ -1110,18 +1110,16 @@
 pName);%0A
-%09%09
 %09%09%09%7D els
@@ -1118,34 +1118,32 @@
 %09%09%09%7D else %7B%0A%09%09%09%09
-%09%09
 Util.LOGGER.info
@@ -1193,22 +1193,18 @@
 s%22);%0A%09%09%09
-%09%09%7D%0A%09%09
+%7D%0A
 %09%09%7D else
@@ -1209,18 +1209,16 @@
 se %7B%0A%09%09%09
-%09
-%09
 // delet
@@ -1238,18 +1238,16 @@
 content%0A
-%09%09
 %09%09%09File 
@@ -1298,26 +1298,24 @@
 %25s%25s%22,%0A%09%09%09%09%09
-%09%09
 Util.getCont
@@ -1335,18 +1335,16 @@
 ),%0A%09%09%09%09%09
-%09
-%09
 customer
@@ -1349,18 +1349,16 @@
 erName,%0A
-%09%09
 %09%09%09%09%09Fil
@@ -1375,18 +1375,16 @@
 r,%0A%09%09%09%09%09
-%09
-%09
 bean.get
@@ -1407,18 +1407,16 @@
 me()));%0A
-%09%09
 %09%09%09if (b
@@ -1433,26 +1433,24 @@
 ts()) %7B%0A%09%09%09%09
-%09%09
 Util.LOGGER.
@@ -1502,18 +1502,16 @@
 ath());%0A
-%09%09
 %09%09%09%09File
@@ -1531,26 +1531,24 @@
 ackup);%0A%09%09%09%09
-%09%09
 Util.LOGGER.
@@ -1602,18 +1602,16 @@
 ());%0A%09%09%09
-%09
-%09
 %7D else %7B
@@ -1611,18 +1611,16 @@
  else %7B%0A
-%09%09
 %09%09%09%09Util
@@ -1700,21 +1700,15 @@
 %0A%09%09%09
-%09%09%7D%0A%09%09
+%7D%0A
 %09%09%7D%0A%0A
-%09%09
 %09%09//
@@ -1738,18 +1738,16 @@
 ackup%0A%09%09
-%09
-%09
 bean.set
@@ -1772,18 +1772,16 @@
 (null);%0A
-%09%09
 %09%09bean.s

Fix indentation.