server/src/main/java/org/iri_research/renkan/rest/SpacesResource.java
author ymh <ymh.work@gmail.com>
Wed, 03 Apr 2013 23:36:05 +0200
changeset 135 f3957d594203
parent 71 9af0874ce43f
child 220 ecbb104cf3b6
permissions -rw-r--r--
Replace UUID.RandomUUID by type 1 uuids

package org.iri_research.renkan.rest;


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

import javax.ws.rs.Path;

import org.iri_research.renkan.Constants;
import org.iri_research.renkan.models.Space;
import org.iri_research.renkan.repositories.IRenkanRepository;
import org.iri_research.renkan.repositories.SpacesRepository;
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("spaces")
@Component
public class SpacesResource extends RenkanResource<Space, String> {
	
	@SuppressWarnings("unused")
	private Logger logger = LoggerFactory.getLogger(SpacesResource.class);
	
	private String[] spaceObjectListFieldList = {"created_by","bin_config","image"};
	
	@Autowired
	private SpacesRepository spacesRepository;
		
	@Override
	protected IRenkanRepository<Space, String> getRepository() {		
		return spacesRepository;
	}


	@Override
	protected String getNewId() {
		return Constants.UUID_GENERATOR.generate().toString();
	}


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


	@Override
	protected List<String> getObjectListFieldList() {
		ArrayList<String> fieldList = new ArrayList<>(this.baseObjectListFieldList.length + this.spaceObjectListFieldList.length);
		fieldList.addAll(Arrays.asList(this.baseObjectListFieldList));
		fieldList.addAll(Arrays.asList(this.spaceObjectListFieldList));
		return fieldList;
	}


}