package org.opentosca.csarrepo.service;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opentosca.csarrepo.exception.PersistenceException;
import org.opentosca.csarrepo.model.Csar;
import org.opentosca.csarrepo.model.repository.CsarRepository;

/**
 * @author eiselems (marcus.eisele@gmail.com), Dennis Przytarski
 *
 */
public class CreateCsarService extends AbstractService {

	private static final Logger LOGGER = LogManager.getLogger(CreateCsarService.class);

	/**
	 * @param userId
	 * @param file
	 */
	public CreateCsarService(long userId, String name) {
		super(userId);

		CsarRepository csarRepo = new CsarRepository();
		try {
			Csar csar = new Csar();
			csar.setName(name);
			csarRepo.save(csar);
		} catch (PersistenceException e) {
			this.addError(e.getMessage());
			LOGGER.error(e);
		}
	}

	public boolean getResult() {
		super.logInvalidResultAccess("getResult");

		return !this.hasErrors();
	}

}

@@ -420,16 +420,36 @@
 vice %7B%0A%0A
+%09long csarId = -1;%0A%0A
 %09private
@@ -774,16 +774,42 @@
 (csar);%0A
+%09%09%09csarId = csar.getId();%0A
 %09%09%7D catc
@@ -837,16 +837,16 @@
 on e) %7B%0A
-
 %09%09%09this.
@@ -911,15 +911,12 @@
 lic 
-boolean
+long
  get
@@ -985,25 +985,14 @@
 urn 
-!this.hasErrors()
+csarId
 ;%0A%09%7D

return id, CreateCsarService.getResults refs #149