server/src/main/java/org/iri_research/renkan/rest/ProjectsResource.java
author ymh <ymh.work@gmail.com>
Sun, 17 Mar 2013 02:24:56 +0100
changeset 92 1723936b3836
parent 71 9af0874ce43f
child 134 f9716d086744
permissions -rw-r--r--
- Add recursive delete for project - correct copy - add unit tests

package org.iri_research.renkan.rest;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import javax.ws.rs.Path;

import org.iri_research.renkan.models.Project;
import org.iri_research.renkan.repositories.IRenkanRepository;
import org.iri_research.renkan.repositories.ProjectsRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sun.jersey.spi.resource.Singleton;


@Singleton
@Path("projects")
@Component
public class ProjectsResource extends RenkanResource<Project, String> {
	
	@SuppressWarnings("unused")
	private Logger logger = LoggerFactory.getLogger(ProjectsResource.class);
	
	@Autowired
	private ProjectsRepository projectsRepository;

	@Override
	protected IRenkanRepository<Project, String> getRepository() {
		return this.projectsRepository;
	}

	@Override
	protected String getNewId() {
		return UUID.randomUUID().toString();
	}

	@Override
	protected void prepareObject(Project obj) {
		if(obj.getCreated() == null) {
			obj.setCreated(new Date());
		}
	}

	@Override
	protected List<String> getObjectListFieldList() {
		return Arrays.asList(this.baseObjectListFieldList);
	}	
	
	@Override
	protected void doDeleteObject(String objectId) {
		this.projectsRepository.deleteRecursive(objectId);
	}

}