repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
edwise/complete-spring-project | src/test/java/com/edwise/completespring/dbutils/DataLoaderTest.java | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/entities/UserAccount.java
// @Document(collection = "users")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class UserAccount {
//
// @Id
// private Long id;
//
// private String username;
// private String password;
//
// @NonNull
// private UserAccountType userType = UserAccountType.REST_USER;
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
| import com.edwise.completespring.entities.Book;
import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.entities.UserAccount;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.security.crypto.password.PasswordEncoder;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; | package com.edwise.completespring.dbutils;
@RunWith(MockitoJUnitRunner.class)
public class DataLoaderTest {
private static final int TWO_TIMES = 2;
private static final int FOUR_TIMES = 4;
@Mock
private BookRepository bookRepository;
@Mock | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/entities/UserAccount.java
// @Document(collection = "users")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class UserAccount {
//
// @Id
// private Long id;
//
// private String username;
// private String password;
//
// @NonNull
// private UserAccountType userType = UserAccountType.REST_USER;
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
// Path: src/test/java/com/edwise/completespring/dbutils/DataLoaderTest.java
import com.edwise.completespring.entities.Book;
import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.entities.UserAccount;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.security.crypto.password.PasswordEncoder;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
package com.edwise.completespring.dbutils;
@RunWith(MockitoJUnitRunner.class)
public class DataLoaderTest {
private static final int TWO_TIMES = 2;
private static final int FOUR_TIMES = 4;
@Mock
private BookRepository bookRepository;
@Mock | private UserAccountRepository userAccountRepository; |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/dbutils/DataLoaderTest.java | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/entities/UserAccount.java
// @Document(collection = "users")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class UserAccount {
//
// @Id
// private Long id;
//
// private String username;
// private String password;
//
// @NonNull
// private UserAccountType userType = UserAccountType.REST_USER;
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
| import com.edwise.completespring.entities.Book;
import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.entities.UserAccount;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.security.crypto.password.PasswordEncoder;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; | package com.edwise.completespring.dbutils;
@RunWith(MockitoJUnitRunner.class)
public class DataLoaderTest {
private static final int TWO_TIMES = 2;
private static final int FOUR_TIMES = 4;
@Mock
private BookRepository bookRepository;
@Mock
private UserAccountRepository userAccountRepository;
@Mock | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/entities/UserAccount.java
// @Document(collection = "users")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class UserAccount {
//
// @Id
// private Long id;
//
// private String username;
// private String password;
//
// @NonNull
// private UserAccountType userType = UserAccountType.REST_USER;
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
// Path: src/test/java/com/edwise/completespring/dbutils/DataLoaderTest.java
import com.edwise.completespring.entities.Book;
import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.entities.UserAccount;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.security.crypto.password.PasswordEncoder;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
package com.edwise.completespring.dbutils;
@RunWith(MockitoJUnitRunner.class)
public class DataLoaderTest {
private static final int TWO_TIMES = 2;
private static final int FOUR_TIMES = 4;
@Mock
private BookRepository bookRepository;
@Mock
private UserAccountRepository userAccountRepository;
@Mock | private SequenceIdRepository sequenceRepository; |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/dbutils/DataLoaderTest.java | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/entities/UserAccount.java
// @Document(collection = "users")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class UserAccount {
//
// @Id
// private Long id;
//
// private String username;
// private String password;
//
// @NonNull
// private UserAccountType userType = UserAccountType.REST_USER;
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
| import com.edwise.completespring.entities.Book;
import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.entities.UserAccount;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.security.crypto.password.PasswordEncoder;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; | package com.edwise.completespring.dbutils;
@RunWith(MockitoJUnitRunner.class)
public class DataLoaderTest {
private static final int TWO_TIMES = 2;
private static final int FOUR_TIMES = 4;
@Mock
private BookRepository bookRepository;
@Mock
private UserAccountRepository userAccountRepository;
@Mock
private SequenceIdRepository sequenceRepository;
@Mock
private PasswordEncoder passwordEncoder;
@InjectMocks
private DataLoader dataLoader;
@Test
public void testFillDBData() {
dataLoader.fillDBData();
verifyRepositoriesCalls();
}
private void verifyRepositoriesCalls() { | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/entities/UserAccount.java
// @Document(collection = "users")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class UserAccount {
//
// @Id
// private Long id;
//
// private String username;
// private String password;
//
// @NonNull
// private UserAccountType userType = UserAccountType.REST_USER;
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
// Path: src/test/java/com/edwise/completespring/dbutils/DataLoaderTest.java
import com.edwise.completespring.entities.Book;
import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.entities.UserAccount;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.security.crypto.password.PasswordEncoder;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
package com.edwise.completespring.dbutils;
@RunWith(MockitoJUnitRunner.class)
public class DataLoaderTest {
private static final int TWO_TIMES = 2;
private static final int FOUR_TIMES = 4;
@Mock
private BookRepository bookRepository;
@Mock
private UserAccountRepository userAccountRepository;
@Mock
private SequenceIdRepository sequenceRepository;
@Mock
private PasswordEncoder passwordEncoder;
@InjectMocks
private DataLoader dataLoader;
@Test
public void testFillDBData() {
dataLoader.fillDBData();
verifyRepositoriesCalls();
}
private void verifyRepositoriesCalls() { | verify(sequenceRepository, times(TWO_TIMES)).save(any(SequenceId.class)); |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/dbutils/DataLoaderTest.java | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/entities/UserAccount.java
// @Document(collection = "users")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class UserAccount {
//
// @Id
// private Long id;
//
// private String username;
// private String password;
//
// @NonNull
// private UserAccountType userType = UserAccountType.REST_USER;
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
| import com.edwise.completespring.entities.Book;
import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.entities.UserAccount;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.security.crypto.password.PasswordEncoder;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; | package com.edwise.completespring.dbutils;
@RunWith(MockitoJUnitRunner.class)
public class DataLoaderTest {
private static final int TWO_TIMES = 2;
private static final int FOUR_TIMES = 4;
@Mock
private BookRepository bookRepository;
@Mock
private UserAccountRepository userAccountRepository;
@Mock
private SequenceIdRepository sequenceRepository;
@Mock
private PasswordEncoder passwordEncoder;
@InjectMocks
private DataLoader dataLoader;
@Test
public void testFillDBData() {
dataLoader.fillDBData();
verifyRepositoriesCalls();
}
private void verifyRepositoriesCalls() {
verify(sequenceRepository, times(TWO_TIMES)).save(any(SequenceId.class));
verify(bookRepository).deleteAll(); | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/entities/UserAccount.java
// @Document(collection = "users")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class UserAccount {
//
// @Id
// private Long id;
//
// private String username;
// private String password;
//
// @NonNull
// private UserAccountType userType = UserAccountType.REST_USER;
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
// Path: src/test/java/com/edwise/completespring/dbutils/DataLoaderTest.java
import com.edwise.completespring.entities.Book;
import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.entities.UserAccount;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.security.crypto.password.PasswordEncoder;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
package com.edwise.completespring.dbutils;
@RunWith(MockitoJUnitRunner.class)
public class DataLoaderTest {
private static final int TWO_TIMES = 2;
private static final int FOUR_TIMES = 4;
@Mock
private BookRepository bookRepository;
@Mock
private UserAccountRepository userAccountRepository;
@Mock
private SequenceIdRepository sequenceRepository;
@Mock
private PasswordEncoder passwordEncoder;
@InjectMocks
private DataLoader dataLoader;
@Test
public void testFillDBData() {
dataLoader.fillDBData();
verifyRepositoriesCalls();
}
private void verifyRepositoriesCalls() {
verify(sequenceRepository, times(TWO_TIMES)).save(any(SequenceId.class));
verify(bookRepository).deleteAll(); | verify(bookRepository, times(FOUR_TIMES)).save(any(Book.class)); |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/dbutils/DataLoaderTest.java | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/entities/UserAccount.java
// @Document(collection = "users")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class UserAccount {
//
// @Id
// private Long id;
//
// private String username;
// private String password;
//
// @NonNull
// private UserAccountType userType = UserAccountType.REST_USER;
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
| import com.edwise.completespring.entities.Book;
import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.entities.UserAccount;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.security.crypto.password.PasswordEncoder;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; | package com.edwise.completespring.dbutils;
@RunWith(MockitoJUnitRunner.class)
public class DataLoaderTest {
private static final int TWO_TIMES = 2;
private static final int FOUR_TIMES = 4;
@Mock
private BookRepository bookRepository;
@Mock
private UserAccountRepository userAccountRepository;
@Mock
private SequenceIdRepository sequenceRepository;
@Mock
private PasswordEncoder passwordEncoder;
@InjectMocks
private DataLoader dataLoader;
@Test
public void testFillDBData() {
dataLoader.fillDBData();
verifyRepositoriesCalls();
}
private void verifyRepositoriesCalls() {
verify(sequenceRepository, times(TWO_TIMES)).save(any(SequenceId.class));
verify(bookRepository).deleteAll();
verify(bookRepository, times(FOUR_TIMES)).save(any(Book.class));
verify(userAccountRepository).deleteAll();
verify(passwordEncoder, times(TWO_TIMES)).encode(any()); | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/entities/UserAccount.java
// @Document(collection = "users")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class UserAccount {
//
// @Id
// private Long id;
//
// private String username;
// private String password;
//
// @NonNull
// private UserAccountType userType = UserAccountType.REST_USER;
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
// Path: src/test/java/com/edwise/completespring/dbutils/DataLoaderTest.java
import com.edwise.completespring.entities.Book;
import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.entities.UserAccount;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.security.crypto.password.PasswordEncoder;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
package com.edwise.completespring.dbutils;
@RunWith(MockitoJUnitRunner.class)
public class DataLoaderTest {
private static final int TWO_TIMES = 2;
private static final int FOUR_TIMES = 4;
@Mock
private BookRepository bookRepository;
@Mock
private UserAccountRepository userAccountRepository;
@Mock
private SequenceIdRepository sequenceRepository;
@Mock
private PasswordEncoder passwordEncoder;
@InjectMocks
private DataLoader dataLoader;
@Test
public void testFillDBData() {
dataLoader.fillDBData();
verifyRepositoriesCalls();
}
private void verifyRepositoriesCalls() {
verify(sequenceRepository, times(TWO_TIMES)).save(any(SequenceId.class));
verify(bookRepository).deleteAll();
verify(bookRepository, times(FOUR_TIMES)).save(any(Book.class));
verify(userAccountRepository).deleteAll();
verify(passwordEncoder, times(TWO_TIMES)).encode(any()); | verify(userAccountRepository, times(TWO_TIMES)).save(any(UserAccount.class)); |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/dbutils/DataLoader.java | // Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
//
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
// public static final String BOOK_COLLECTION = "books";
// private static final String BOOK_NOT_FOUND_MSG = "Book not found";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private SequenceIdRepository sequenceIdRepository;
//
// @Override
// public List<Book> findAll() {
// return bookRepository.findAll();
// }
//
// @Override
// public Book save(Book book) {
// return bookRepository.save(book);
// }
//
// @Override
// public Book findOne(Long id) {
// Optional<Book> result = bookRepository.findById(id);
// if (!result.isPresent()) {
// throw new NotFoundException(BOOK_NOT_FOUND_MSG);
// }
// return result.get();
// }
//
// @Override
// public void delete(Long id) {
// bookRepository.deleteById(id);
// }
//
// @Override
// public Book create(Book book) {
// Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
// book.setId(id);
//
// return bookRepository.save(book);
// }
//
// @Override
// public List<Book> findByTitle(String title) {
// return bookRepository.findByTitle(title);
// }
//
// @Override
// public List<Book> findByReleaseDate(LocalDate releaseDate) {
// return bookRepository.findByReleaseDate(releaseDate);
// }
// }
| import com.edwise.completespring.entities.*;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import com.edwise.completespring.services.impl.BookServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collections; | package com.edwise.completespring.dbutils;
@Slf4j
@Component
public class DataLoader {
private static final String USERACCOUNTS_COLLECTION = "users";
private static final Long BOOKS_INITIAL_SEQUENCE = 4L;
private static final Long USERACCOUNTS_INITIAL_SEQUENCE = 3L;
public static final Long BOOK_ID_1 = 1L;
public static final Long BOOK_ID_2 = 2L;
public static final Long BOOK_ID_3 = 3L;
private static final Long BOOK_ID_4 = 4L;
private static final Long USER_ID_1 = 1L;
private static final Long USER_ID_2 = 2L;
public static final String USER = "user1";
public static final String PASSWORD_USER = "password1";
public static final String ADMIN = "admin";
public static final String PASSWORD_ADMIN = "password1234";
@Autowired | // Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
//
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
// public static final String BOOK_COLLECTION = "books";
// private static final String BOOK_NOT_FOUND_MSG = "Book not found";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private SequenceIdRepository sequenceIdRepository;
//
// @Override
// public List<Book> findAll() {
// return bookRepository.findAll();
// }
//
// @Override
// public Book save(Book book) {
// return bookRepository.save(book);
// }
//
// @Override
// public Book findOne(Long id) {
// Optional<Book> result = bookRepository.findById(id);
// if (!result.isPresent()) {
// throw new NotFoundException(BOOK_NOT_FOUND_MSG);
// }
// return result.get();
// }
//
// @Override
// public void delete(Long id) {
// bookRepository.deleteById(id);
// }
//
// @Override
// public Book create(Book book) {
// Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
// book.setId(id);
//
// return bookRepository.save(book);
// }
//
// @Override
// public List<Book> findByTitle(String title) {
// return bookRepository.findByTitle(title);
// }
//
// @Override
// public List<Book> findByReleaseDate(LocalDate releaseDate) {
// return bookRepository.findByReleaseDate(releaseDate);
// }
// }
// Path: src/main/java/com/edwise/completespring/dbutils/DataLoader.java
import com.edwise.completespring.entities.*;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import com.edwise.completespring.services.impl.BookServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collections;
package com.edwise.completespring.dbutils;
@Slf4j
@Component
public class DataLoader {
private static final String USERACCOUNTS_COLLECTION = "users";
private static final Long BOOKS_INITIAL_SEQUENCE = 4L;
private static final Long USERACCOUNTS_INITIAL_SEQUENCE = 3L;
public static final Long BOOK_ID_1 = 1L;
public static final Long BOOK_ID_2 = 2L;
public static final Long BOOK_ID_3 = 3L;
private static final Long BOOK_ID_4 = 4L;
private static final Long USER_ID_1 = 1L;
private static final Long USER_ID_2 = 2L;
public static final String USER = "user1";
public static final String PASSWORD_USER = "password1";
public static final String ADMIN = "admin";
public static final String PASSWORD_ADMIN = "password1234";
@Autowired | private BookRepository bookRepository; |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/dbutils/DataLoader.java | // Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
//
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
// public static final String BOOK_COLLECTION = "books";
// private static final String BOOK_NOT_FOUND_MSG = "Book not found";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private SequenceIdRepository sequenceIdRepository;
//
// @Override
// public List<Book> findAll() {
// return bookRepository.findAll();
// }
//
// @Override
// public Book save(Book book) {
// return bookRepository.save(book);
// }
//
// @Override
// public Book findOne(Long id) {
// Optional<Book> result = bookRepository.findById(id);
// if (!result.isPresent()) {
// throw new NotFoundException(BOOK_NOT_FOUND_MSG);
// }
// return result.get();
// }
//
// @Override
// public void delete(Long id) {
// bookRepository.deleteById(id);
// }
//
// @Override
// public Book create(Book book) {
// Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
// book.setId(id);
//
// return bookRepository.save(book);
// }
//
// @Override
// public List<Book> findByTitle(String title) {
// return bookRepository.findByTitle(title);
// }
//
// @Override
// public List<Book> findByReleaseDate(LocalDate releaseDate) {
// return bookRepository.findByReleaseDate(releaseDate);
// }
// }
| import com.edwise.completespring.entities.*;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import com.edwise.completespring.services.impl.BookServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collections; | package com.edwise.completespring.dbutils;
@Slf4j
@Component
public class DataLoader {
private static final String USERACCOUNTS_COLLECTION = "users";
private static final Long BOOKS_INITIAL_SEQUENCE = 4L;
private static final Long USERACCOUNTS_INITIAL_SEQUENCE = 3L;
public static final Long BOOK_ID_1 = 1L;
public static final Long BOOK_ID_2 = 2L;
public static final Long BOOK_ID_3 = 3L;
private static final Long BOOK_ID_4 = 4L;
private static final Long USER_ID_1 = 1L;
private static final Long USER_ID_2 = 2L;
public static final String USER = "user1";
public static final String PASSWORD_USER = "password1";
public static final String ADMIN = "admin";
public static final String PASSWORD_ADMIN = "password1234";
@Autowired
private BookRepository bookRepository;
@Autowired | // Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
//
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
// public static final String BOOK_COLLECTION = "books";
// private static final String BOOK_NOT_FOUND_MSG = "Book not found";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private SequenceIdRepository sequenceIdRepository;
//
// @Override
// public List<Book> findAll() {
// return bookRepository.findAll();
// }
//
// @Override
// public Book save(Book book) {
// return bookRepository.save(book);
// }
//
// @Override
// public Book findOne(Long id) {
// Optional<Book> result = bookRepository.findById(id);
// if (!result.isPresent()) {
// throw new NotFoundException(BOOK_NOT_FOUND_MSG);
// }
// return result.get();
// }
//
// @Override
// public void delete(Long id) {
// bookRepository.deleteById(id);
// }
//
// @Override
// public Book create(Book book) {
// Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
// book.setId(id);
//
// return bookRepository.save(book);
// }
//
// @Override
// public List<Book> findByTitle(String title) {
// return bookRepository.findByTitle(title);
// }
//
// @Override
// public List<Book> findByReleaseDate(LocalDate releaseDate) {
// return bookRepository.findByReleaseDate(releaseDate);
// }
// }
// Path: src/main/java/com/edwise/completespring/dbutils/DataLoader.java
import com.edwise.completespring.entities.*;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import com.edwise.completespring.services.impl.BookServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collections;
package com.edwise.completespring.dbutils;
@Slf4j
@Component
public class DataLoader {
private static final String USERACCOUNTS_COLLECTION = "users";
private static final Long BOOKS_INITIAL_SEQUENCE = 4L;
private static final Long USERACCOUNTS_INITIAL_SEQUENCE = 3L;
public static final Long BOOK_ID_1 = 1L;
public static final Long BOOK_ID_2 = 2L;
public static final Long BOOK_ID_3 = 3L;
private static final Long BOOK_ID_4 = 4L;
private static final Long USER_ID_1 = 1L;
private static final Long USER_ID_2 = 2L;
public static final String USER = "user1";
public static final String PASSWORD_USER = "password1";
public static final String ADMIN = "admin";
public static final String PASSWORD_ADMIN = "password1234";
@Autowired
private BookRepository bookRepository;
@Autowired | private UserAccountRepository userAccountRepository; |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/dbutils/DataLoader.java | // Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
//
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
// public static final String BOOK_COLLECTION = "books";
// private static final String BOOK_NOT_FOUND_MSG = "Book not found";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private SequenceIdRepository sequenceIdRepository;
//
// @Override
// public List<Book> findAll() {
// return bookRepository.findAll();
// }
//
// @Override
// public Book save(Book book) {
// return bookRepository.save(book);
// }
//
// @Override
// public Book findOne(Long id) {
// Optional<Book> result = bookRepository.findById(id);
// if (!result.isPresent()) {
// throw new NotFoundException(BOOK_NOT_FOUND_MSG);
// }
// return result.get();
// }
//
// @Override
// public void delete(Long id) {
// bookRepository.deleteById(id);
// }
//
// @Override
// public Book create(Book book) {
// Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
// book.setId(id);
//
// return bookRepository.save(book);
// }
//
// @Override
// public List<Book> findByTitle(String title) {
// return bookRepository.findByTitle(title);
// }
//
// @Override
// public List<Book> findByReleaseDate(LocalDate releaseDate) {
// return bookRepository.findByReleaseDate(releaseDate);
// }
// }
| import com.edwise.completespring.entities.*;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import com.edwise.completespring.services.impl.BookServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collections; | package com.edwise.completespring.dbutils;
@Slf4j
@Component
public class DataLoader {
private static final String USERACCOUNTS_COLLECTION = "users";
private static final Long BOOKS_INITIAL_SEQUENCE = 4L;
private static final Long USERACCOUNTS_INITIAL_SEQUENCE = 3L;
public static final Long BOOK_ID_1 = 1L;
public static final Long BOOK_ID_2 = 2L;
public static final Long BOOK_ID_3 = 3L;
private static final Long BOOK_ID_4 = 4L;
private static final Long USER_ID_1 = 1L;
private static final Long USER_ID_2 = 2L;
public static final String USER = "user1";
public static final String PASSWORD_USER = "password1";
public static final String ADMIN = "admin";
public static final String PASSWORD_ADMIN = "password1234";
@Autowired
private BookRepository bookRepository;
@Autowired
private UserAccountRepository userAccountRepository;
@Autowired | // Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
//
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
// public static final String BOOK_COLLECTION = "books";
// private static final String BOOK_NOT_FOUND_MSG = "Book not found";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private SequenceIdRepository sequenceIdRepository;
//
// @Override
// public List<Book> findAll() {
// return bookRepository.findAll();
// }
//
// @Override
// public Book save(Book book) {
// return bookRepository.save(book);
// }
//
// @Override
// public Book findOne(Long id) {
// Optional<Book> result = bookRepository.findById(id);
// if (!result.isPresent()) {
// throw new NotFoundException(BOOK_NOT_FOUND_MSG);
// }
// return result.get();
// }
//
// @Override
// public void delete(Long id) {
// bookRepository.deleteById(id);
// }
//
// @Override
// public Book create(Book book) {
// Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
// book.setId(id);
//
// return bookRepository.save(book);
// }
//
// @Override
// public List<Book> findByTitle(String title) {
// return bookRepository.findByTitle(title);
// }
//
// @Override
// public List<Book> findByReleaseDate(LocalDate releaseDate) {
// return bookRepository.findByReleaseDate(releaseDate);
// }
// }
// Path: src/main/java/com/edwise/completespring/dbutils/DataLoader.java
import com.edwise.completespring.entities.*;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import com.edwise.completespring.services.impl.BookServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collections;
package com.edwise.completespring.dbutils;
@Slf4j
@Component
public class DataLoader {
private static final String USERACCOUNTS_COLLECTION = "users";
private static final Long BOOKS_INITIAL_SEQUENCE = 4L;
private static final Long USERACCOUNTS_INITIAL_SEQUENCE = 3L;
public static final Long BOOK_ID_1 = 1L;
public static final Long BOOK_ID_2 = 2L;
public static final Long BOOK_ID_3 = 3L;
private static final Long BOOK_ID_4 = 4L;
private static final Long USER_ID_1 = 1L;
private static final Long USER_ID_2 = 2L;
public static final String USER = "user1";
public static final String PASSWORD_USER = "password1";
public static final String ADMIN = "admin";
public static final String PASSWORD_ADMIN = "password1234";
@Autowired
private BookRepository bookRepository;
@Autowired
private UserAccountRepository userAccountRepository;
@Autowired | private SequenceIdRepository sequenceRepository; |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/dbutils/DataLoader.java | // Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
//
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
// public static final String BOOK_COLLECTION = "books";
// private static final String BOOK_NOT_FOUND_MSG = "Book not found";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private SequenceIdRepository sequenceIdRepository;
//
// @Override
// public List<Book> findAll() {
// return bookRepository.findAll();
// }
//
// @Override
// public Book save(Book book) {
// return bookRepository.save(book);
// }
//
// @Override
// public Book findOne(Long id) {
// Optional<Book> result = bookRepository.findById(id);
// if (!result.isPresent()) {
// throw new NotFoundException(BOOK_NOT_FOUND_MSG);
// }
// return result.get();
// }
//
// @Override
// public void delete(Long id) {
// bookRepository.deleteById(id);
// }
//
// @Override
// public Book create(Book book) {
// Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
// book.setId(id);
//
// return bookRepository.save(book);
// }
//
// @Override
// public List<Book> findByTitle(String title) {
// return bookRepository.findByTitle(title);
// }
//
// @Override
// public List<Book> findByReleaseDate(LocalDate releaseDate) {
// return bookRepository.findByReleaseDate(releaseDate);
// }
// }
| import com.edwise.completespring.entities.*;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import com.edwise.completespring.services.impl.BookServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collections; |
public void fillDBData() {
log.info("Filling DB data...");
fillDBUsersData();
fillDBBooksData();
log.info("DB filled with data.");
}
private void fillDBUsersData() {
sequenceRepository.save(new SequenceId()
.setId(USERACCOUNTS_COLLECTION)
.setSeq(USERACCOUNTS_INITIAL_SEQUENCE)
);
userAccountRepository.deleteAll();
Arrays.asList(
new UserAccount()
.setId(USER_ID_1)
.setUsername(USER)
.setPassword(passwordEncoder.encode(PASSWORD_USER))
.setUserType(UserAccountType.REST_USER),
new UserAccount()
.setId(USER_ID_2)
.setUsername(ADMIN)
.setPassword(passwordEncoder.encode(PASSWORD_ADMIN))
.setUserType(UserAccountType.ADMIN_USER))
.forEach(userAccountRepository::save);
}
private void fillDBBooksData() {
sequenceRepository.save(new SequenceId() | // Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
//
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
// public static final String BOOK_COLLECTION = "books";
// private static final String BOOK_NOT_FOUND_MSG = "Book not found";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private SequenceIdRepository sequenceIdRepository;
//
// @Override
// public List<Book> findAll() {
// return bookRepository.findAll();
// }
//
// @Override
// public Book save(Book book) {
// return bookRepository.save(book);
// }
//
// @Override
// public Book findOne(Long id) {
// Optional<Book> result = bookRepository.findById(id);
// if (!result.isPresent()) {
// throw new NotFoundException(BOOK_NOT_FOUND_MSG);
// }
// return result.get();
// }
//
// @Override
// public void delete(Long id) {
// bookRepository.deleteById(id);
// }
//
// @Override
// public Book create(Book book) {
// Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
// book.setId(id);
//
// return bookRepository.save(book);
// }
//
// @Override
// public List<Book> findByTitle(String title) {
// return bookRepository.findByTitle(title);
// }
//
// @Override
// public List<Book> findByReleaseDate(LocalDate releaseDate) {
// return bookRepository.findByReleaseDate(releaseDate);
// }
// }
// Path: src/main/java/com/edwise/completespring/dbutils/DataLoader.java
import com.edwise.completespring.entities.*;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import com.edwise.completespring.services.impl.BookServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collections;
public void fillDBData() {
log.info("Filling DB data...");
fillDBUsersData();
fillDBBooksData();
log.info("DB filled with data.");
}
private void fillDBUsersData() {
sequenceRepository.save(new SequenceId()
.setId(USERACCOUNTS_COLLECTION)
.setSeq(USERACCOUNTS_INITIAL_SEQUENCE)
);
userAccountRepository.deleteAll();
Arrays.asList(
new UserAccount()
.setId(USER_ID_1)
.setUsername(USER)
.setPassword(passwordEncoder.encode(PASSWORD_USER))
.setUserType(UserAccountType.REST_USER),
new UserAccount()
.setId(USER_ID_2)
.setUsername(ADMIN)
.setPassword(passwordEncoder.encode(PASSWORD_ADMIN))
.setUserType(UserAccountType.ADMIN_USER))
.forEach(userAccountRepository::save);
}
private void fillDBBooksData() {
sequenceRepository.save(new SequenceId() | .setId(BookServiceImpl.BOOK_COLLECTION) |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
| import com.edwise.completespring.entities.Book;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.services.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional; | package com.edwise.completespring.services.impl;
@Service
public class BookServiceImpl implements BookService {
public static final String BOOK_COLLECTION = "books";
private static final String BOOK_NOT_FOUND_MSG = "Book not found";
@Autowired | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
import com.edwise.completespring.entities.Book;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.services.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
package com.edwise.completespring.services.impl;
@Service
public class BookServiceImpl implements BookService {
public static final String BOOK_COLLECTION = "books";
private static final String BOOK_NOT_FOUND_MSG = "Book not found";
@Autowired | private BookRepository bookRepository; |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
| import com.edwise.completespring.entities.Book;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.services.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional; | package com.edwise.completespring.services.impl;
@Service
public class BookServiceImpl implements BookService {
public static final String BOOK_COLLECTION = "books";
private static final String BOOK_NOT_FOUND_MSG = "Book not found";
@Autowired
private BookRepository bookRepository;
@Autowired | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
import com.edwise.completespring.entities.Book;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.services.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
package com.edwise.completespring.services.impl;
@Service
public class BookServiceImpl implements BookService {
public static final String BOOK_COLLECTION = "books";
private static final String BOOK_NOT_FOUND_MSG = "Book not found";
@Autowired
private BookRepository bookRepository;
@Autowired | private SequenceIdRepository sequenceIdRepository; |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
| import com.edwise.completespring.entities.Book;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.services.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional; | package com.edwise.completespring.services.impl;
@Service
public class BookServiceImpl implements BookService {
public static final String BOOK_COLLECTION = "books";
private static final String BOOK_NOT_FOUND_MSG = "Book not found";
@Autowired
private BookRepository bookRepository;
@Autowired
private SequenceIdRepository sequenceIdRepository;
@Override | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
import com.edwise.completespring.entities.Book;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.services.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
package com.edwise.completespring.services.impl;
@Service
public class BookServiceImpl implements BookService {
public static final String BOOK_COLLECTION = "books";
private static final String BOOK_NOT_FOUND_MSG = "Book not found";
@Autowired
private BookRepository bookRepository;
@Autowired
private SequenceIdRepository sequenceIdRepository;
@Override | public List<Book> findAll() { |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
| import com.edwise.completespring.entities.Book;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.services.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional; | package com.edwise.completespring.services.impl;
@Service
public class BookServiceImpl implements BookService {
public static final String BOOK_COLLECTION = "books";
private static final String BOOK_NOT_FOUND_MSG = "Book not found";
@Autowired
private BookRepository bookRepository;
@Autowired
private SequenceIdRepository sequenceIdRepository;
@Override
public List<Book> findAll() {
return bookRepository.findAll();
}
@Override
public Book save(Book book) {
return bookRepository.save(book);
}
@Override
public Book findOne(Long id) {
Optional<Book> result = bookRepository.findById(id);
if (!result.isPresent()) { | // Path: src/main/java/com/edwise/completespring/entities/Book.java
// @Document(collection = "books")
// @ApiModel(value = "Book entity", description = "Complete info of a entity book")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Book {
//
// @ApiModelProperty(value = "The id of the book")
// @Id
// private Long id;
//
// @ApiModelProperty(value = "The title of the book", required = true)
// @NotEmpty
// private String title;
//
// @ApiModelProperty(value = "The authors of the book", required = true)
// @Valid
// private List<Author> authors;
//
// @ApiModelProperty(value = "The isbn of the book", required = true)
// @NotEmpty
// private String isbn;
//
// @ApiModelProperty(value = "The release date of the book", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate releaseDate;
//
// @ApiModelProperty(value = "The publisher of the book", required = true)
// @Valid
// @NotNull
// private Publisher publisher;
//
// public Book copyFrom(Book other) {
// this.title = other.title;
// if (other.authors != null) {
// this.authors = new ArrayList<>();
// this.authors.addAll(other.authors.stream().map(new Author()::copyFrom).collect(Collectors.toList()));
// }
// this.isbn = other.isbn;
// this.releaseDate = other.releaseDate;
// if (other.publisher != null) {
// this.publisher = new Publisher().copyFrom(other.publisher);
// }
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
//
// List<Book> findByTitle(String title);
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
// void save(SequenceId sequenceId);
//
// long getNextSequenceId(String key);
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
import com.edwise.completespring.entities.Book;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.services.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
package com.edwise.completespring.services.impl;
@Service
public class BookServiceImpl implements BookService {
public static final String BOOK_COLLECTION = "books";
private static final String BOOK_NOT_FOUND_MSG = "Book not found";
@Autowired
private BookRepository bookRepository;
@Autowired
private SequenceIdRepository sequenceIdRepository;
@Override
public List<Book> findAll() {
return bookRepository.findAll();
}
@Override
public Book save(Book book) {
return bookRepository.save(book);
}
@Override
public Book findOne(Long id) {
Optional<Book> result = bookRepository.findById(id);
if (!result.isPresent()) { | throw new NotFoundException(BOOK_NOT_FOUND_MSG); |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/repositories/impl/SequenceIdRepositoryImplTest.java | // Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/SequenceException.java
// public class SequenceException extends RuntimeException {
//
// public SequenceException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
// public static final String BOOK_COLLECTION = "books";
// private static final String BOOK_NOT_FOUND_MSG = "Book not found";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private SequenceIdRepository sequenceIdRepository;
//
// @Override
// public List<Book> findAll() {
// return bookRepository.findAll();
// }
//
// @Override
// public Book save(Book book) {
// return bookRepository.save(book);
// }
//
// @Override
// public Book findOne(Long id) {
// Optional<Book> result = bookRepository.findById(id);
// if (!result.isPresent()) {
// throw new NotFoundException(BOOK_NOT_FOUND_MSG);
// }
// return result.get();
// }
//
// @Override
// public void delete(Long id) {
// bookRepository.deleteById(id);
// }
//
// @Override
// public Book create(Book book) {
// Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
// book.setId(id);
//
// return bookRepository.save(book);
// }
//
// @Override
// public List<Book> findByTitle(String title) {
// return bookRepository.findByTitle(title);
// }
//
// @Override
// public List<Book> findByReleaseDate(LocalDate releaseDate) {
// return bookRepository.findByReleaseDate(releaseDate);
// }
// }
| import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.exceptions.SequenceException;
import com.edwise.completespring.services.impl.BookServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.mongodb.core.FindAndModifyOptions;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*; | package com.edwise.completespring.repositories.impl;
@RunWith(MockitoJUnitRunner.class)
public class SequenceIdRepositoryImplTest {
private static final long TEST_SEQUENCE_ID = 7L;
private static final int ONE_TIME = 1;
@Mock
private MongoOperations mongoOperation;
@InjectMocks
private SequenceIdRepositoryImpl repository = new SequenceIdRepositoryImpl();
@Test
public void testGetNextSequenceId() {
when(mongoOperation.findAndModify(any(Query.class), any(Update.class), any(FindAndModifyOptions.class), | // Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/SequenceException.java
// public class SequenceException extends RuntimeException {
//
// public SequenceException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
// public static final String BOOK_COLLECTION = "books";
// private static final String BOOK_NOT_FOUND_MSG = "Book not found";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private SequenceIdRepository sequenceIdRepository;
//
// @Override
// public List<Book> findAll() {
// return bookRepository.findAll();
// }
//
// @Override
// public Book save(Book book) {
// return bookRepository.save(book);
// }
//
// @Override
// public Book findOne(Long id) {
// Optional<Book> result = bookRepository.findById(id);
// if (!result.isPresent()) {
// throw new NotFoundException(BOOK_NOT_FOUND_MSG);
// }
// return result.get();
// }
//
// @Override
// public void delete(Long id) {
// bookRepository.deleteById(id);
// }
//
// @Override
// public Book create(Book book) {
// Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
// book.setId(id);
//
// return bookRepository.save(book);
// }
//
// @Override
// public List<Book> findByTitle(String title) {
// return bookRepository.findByTitle(title);
// }
//
// @Override
// public List<Book> findByReleaseDate(LocalDate releaseDate) {
// return bookRepository.findByReleaseDate(releaseDate);
// }
// }
// Path: src/test/java/com/edwise/completespring/repositories/impl/SequenceIdRepositoryImplTest.java
import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.exceptions.SequenceException;
import com.edwise.completespring.services.impl.BookServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.mongodb.core.FindAndModifyOptions;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*;
package com.edwise.completespring.repositories.impl;
@RunWith(MockitoJUnitRunner.class)
public class SequenceIdRepositoryImplTest {
private static final long TEST_SEQUENCE_ID = 7L;
private static final int ONE_TIME = 1;
@Mock
private MongoOperations mongoOperation;
@InjectMocks
private SequenceIdRepositoryImpl repository = new SequenceIdRepositoryImpl();
@Test
public void testGetNextSequenceId() {
when(mongoOperation.findAndModify(any(Query.class), any(Update.class), any(FindAndModifyOptions.class), | eq(SequenceId.class))).thenReturn(new SequenceId().setId(BookServiceImpl.BOOK_COLLECTION).setSeq(6L)); |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/repositories/impl/SequenceIdRepositoryImplTest.java | // Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/SequenceException.java
// public class SequenceException extends RuntimeException {
//
// public SequenceException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
// public static final String BOOK_COLLECTION = "books";
// private static final String BOOK_NOT_FOUND_MSG = "Book not found";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private SequenceIdRepository sequenceIdRepository;
//
// @Override
// public List<Book> findAll() {
// return bookRepository.findAll();
// }
//
// @Override
// public Book save(Book book) {
// return bookRepository.save(book);
// }
//
// @Override
// public Book findOne(Long id) {
// Optional<Book> result = bookRepository.findById(id);
// if (!result.isPresent()) {
// throw new NotFoundException(BOOK_NOT_FOUND_MSG);
// }
// return result.get();
// }
//
// @Override
// public void delete(Long id) {
// bookRepository.deleteById(id);
// }
//
// @Override
// public Book create(Book book) {
// Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
// book.setId(id);
//
// return bookRepository.save(book);
// }
//
// @Override
// public List<Book> findByTitle(String title) {
// return bookRepository.findByTitle(title);
// }
//
// @Override
// public List<Book> findByReleaseDate(LocalDate releaseDate) {
// return bookRepository.findByReleaseDate(releaseDate);
// }
// }
| import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.exceptions.SequenceException;
import com.edwise.completespring.services.impl.BookServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.mongodb.core.FindAndModifyOptions;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*; | package com.edwise.completespring.repositories.impl;
@RunWith(MockitoJUnitRunner.class)
public class SequenceIdRepositoryImplTest {
private static final long TEST_SEQUENCE_ID = 7L;
private static final int ONE_TIME = 1;
@Mock
private MongoOperations mongoOperation;
@InjectMocks
private SequenceIdRepositoryImpl repository = new SequenceIdRepositoryImpl();
@Test
public void testGetNextSequenceId() {
when(mongoOperation.findAndModify(any(Query.class), any(Update.class), any(FindAndModifyOptions.class), | // Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/SequenceException.java
// public class SequenceException extends RuntimeException {
//
// public SequenceException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
// public static final String BOOK_COLLECTION = "books";
// private static final String BOOK_NOT_FOUND_MSG = "Book not found";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private SequenceIdRepository sequenceIdRepository;
//
// @Override
// public List<Book> findAll() {
// return bookRepository.findAll();
// }
//
// @Override
// public Book save(Book book) {
// return bookRepository.save(book);
// }
//
// @Override
// public Book findOne(Long id) {
// Optional<Book> result = bookRepository.findById(id);
// if (!result.isPresent()) {
// throw new NotFoundException(BOOK_NOT_FOUND_MSG);
// }
// return result.get();
// }
//
// @Override
// public void delete(Long id) {
// bookRepository.deleteById(id);
// }
//
// @Override
// public Book create(Book book) {
// Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
// book.setId(id);
//
// return bookRepository.save(book);
// }
//
// @Override
// public List<Book> findByTitle(String title) {
// return bookRepository.findByTitle(title);
// }
//
// @Override
// public List<Book> findByReleaseDate(LocalDate releaseDate) {
// return bookRepository.findByReleaseDate(releaseDate);
// }
// }
// Path: src/test/java/com/edwise/completespring/repositories/impl/SequenceIdRepositoryImplTest.java
import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.exceptions.SequenceException;
import com.edwise.completespring.services.impl.BookServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.mongodb.core.FindAndModifyOptions;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*;
package com.edwise.completespring.repositories.impl;
@RunWith(MockitoJUnitRunner.class)
public class SequenceIdRepositoryImplTest {
private static final long TEST_SEQUENCE_ID = 7L;
private static final int ONE_TIME = 1;
@Mock
private MongoOperations mongoOperation;
@InjectMocks
private SequenceIdRepositoryImpl repository = new SequenceIdRepositoryImpl();
@Test
public void testGetNextSequenceId() {
when(mongoOperation.findAndModify(any(Query.class), any(Update.class), any(FindAndModifyOptions.class), | eq(SequenceId.class))).thenReturn(new SequenceId().setId(BookServiceImpl.BOOK_COLLECTION).setSeq(6L)); |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/repositories/impl/SequenceIdRepositoryImplTest.java | // Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/SequenceException.java
// public class SequenceException extends RuntimeException {
//
// public SequenceException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
// public static final String BOOK_COLLECTION = "books";
// private static final String BOOK_NOT_FOUND_MSG = "Book not found";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private SequenceIdRepository sequenceIdRepository;
//
// @Override
// public List<Book> findAll() {
// return bookRepository.findAll();
// }
//
// @Override
// public Book save(Book book) {
// return bookRepository.save(book);
// }
//
// @Override
// public Book findOne(Long id) {
// Optional<Book> result = bookRepository.findById(id);
// if (!result.isPresent()) {
// throw new NotFoundException(BOOK_NOT_FOUND_MSG);
// }
// return result.get();
// }
//
// @Override
// public void delete(Long id) {
// bookRepository.deleteById(id);
// }
//
// @Override
// public Book create(Book book) {
// Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
// book.setId(id);
//
// return bookRepository.save(book);
// }
//
// @Override
// public List<Book> findByTitle(String title) {
// return bookRepository.findByTitle(title);
// }
//
// @Override
// public List<Book> findByReleaseDate(LocalDate releaseDate) {
// return bookRepository.findByReleaseDate(releaseDate);
// }
// }
| import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.exceptions.SequenceException;
import com.edwise.completespring.services.impl.BookServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.mongodb.core.FindAndModifyOptions;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*; | package com.edwise.completespring.repositories.impl;
@RunWith(MockitoJUnitRunner.class)
public class SequenceIdRepositoryImplTest {
private static final long TEST_SEQUENCE_ID = 7L;
private static final int ONE_TIME = 1;
@Mock
private MongoOperations mongoOperation;
@InjectMocks
private SequenceIdRepositoryImpl repository = new SequenceIdRepositoryImpl();
@Test
public void testGetNextSequenceId() {
when(mongoOperation.findAndModify(any(Query.class), any(Update.class), any(FindAndModifyOptions.class),
eq(SequenceId.class))).thenReturn(new SequenceId().setId(BookServiceImpl.BOOK_COLLECTION).setSeq(6L));
long seqId = repository.getNextSequenceId(BookServiceImpl.BOOK_COLLECTION);
assertThat(seqId).as("Should return a valid sequence").isGreaterThan(0);
verify(mongoOperation, times(ONE_TIME)).findAndModify(any(Query.class), any(Update.class),
any(FindAndModifyOptions.class), eq(SequenceId.class));
}
@Test
public void testGetNextSequenceIdWhenNotExistsSequence() {
when(mongoOperation.findAndModify(any(Query.class), any(Update.class), any(FindAndModifyOptions.class),
eq(SequenceId.class))).thenReturn(null);
Throwable thrown = catchThrowable(() -> repository.getNextSequenceId(BookServiceImpl.BOOK_COLLECTION));
assertThat(thrown) | // Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
// @Id
// private String id;
//
// private long seq;
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/SequenceException.java
// public class SequenceException extends RuntimeException {
//
// public SequenceException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
// public static final String BOOK_COLLECTION = "books";
// private static final String BOOK_NOT_FOUND_MSG = "Book not found";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private SequenceIdRepository sequenceIdRepository;
//
// @Override
// public List<Book> findAll() {
// return bookRepository.findAll();
// }
//
// @Override
// public Book save(Book book) {
// return bookRepository.save(book);
// }
//
// @Override
// public Book findOne(Long id) {
// Optional<Book> result = bookRepository.findById(id);
// if (!result.isPresent()) {
// throw new NotFoundException(BOOK_NOT_FOUND_MSG);
// }
// return result.get();
// }
//
// @Override
// public void delete(Long id) {
// bookRepository.deleteById(id);
// }
//
// @Override
// public Book create(Book book) {
// Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
// book.setId(id);
//
// return bookRepository.save(book);
// }
//
// @Override
// public List<Book> findByTitle(String title) {
// return bookRepository.findByTitle(title);
// }
//
// @Override
// public List<Book> findByReleaseDate(LocalDate releaseDate) {
// return bookRepository.findByReleaseDate(releaseDate);
// }
// }
// Path: src/test/java/com/edwise/completespring/repositories/impl/SequenceIdRepositoryImplTest.java
import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.exceptions.SequenceException;
import com.edwise.completespring.services.impl.BookServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.mongodb.core.FindAndModifyOptions;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*;
package com.edwise.completespring.repositories.impl;
@RunWith(MockitoJUnitRunner.class)
public class SequenceIdRepositoryImplTest {
private static final long TEST_SEQUENCE_ID = 7L;
private static final int ONE_TIME = 1;
@Mock
private MongoOperations mongoOperation;
@InjectMocks
private SequenceIdRepositoryImpl repository = new SequenceIdRepositoryImpl();
@Test
public void testGetNextSequenceId() {
when(mongoOperation.findAndModify(any(Query.class), any(Update.class), any(FindAndModifyOptions.class),
eq(SequenceId.class))).thenReturn(new SequenceId().setId(BookServiceImpl.BOOK_COLLECTION).setSeq(6L));
long seqId = repository.getNextSequenceId(BookServiceImpl.BOOK_COLLECTION);
assertThat(seqId).as("Should return a valid sequence").isGreaterThan(0);
verify(mongoOperation, times(ONE_TIME)).findAndModify(any(Query.class), any(Update.class),
any(FindAndModifyOptions.class), eq(SequenceId.class));
}
@Test
public void testGetNextSequenceIdWhenNotExistsSequence() {
when(mongoOperation.findAndModify(any(Query.class), any(Update.class), any(FindAndModifyOptions.class),
eq(SequenceId.class))).thenReturn(null);
Throwable thrown = catchThrowable(() -> repository.getNextSequenceId(BookServiceImpl.BOOK_COLLECTION));
assertThat(thrown) | .isInstanceOf(SequenceException.class) |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/controllers/RestExceptionProcessor.java | // Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/helpers/ErrorInfo.java
// @Accessors(chain = true)
// @EqualsAndHashCode(doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class ErrorInfo implements Serializable {
//
// private static final long serialVersionUID = 673514291953827696L;
//
// @Getter
// @Setter
// private String url;
//
// @Getter
// private List<ErrorItem> errors = new ArrayList<>();
//
// public ErrorInfo addError(String field, String message) {
// errors.add(new ErrorItem().setField(field).setMessage(message));
// return this;
// }
//
// public static ErrorInfo generateErrorInfoFromBindingResult(BindingResult errors) {
// ErrorInfo errorInfo = new ErrorInfo();
// errors.getFieldErrors()
// .forEach(fieldError -> errorInfo.addError(fieldError.getField(), fieldError.getDefaultMessage()));
//
// return errorInfo;
// }
// }
| import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.exceptions.helpers.ErrorInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import javax.servlet.http.HttpServletRequest; | package com.edwise.completespring.controllers;
@ControllerAdvice
@Slf4j
public class RestExceptionProcessor {
private static final String FIELD_ID = "id";
| // Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/helpers/ErrorInfo.java
// @Accessors(chain = true)
// @EqualsAndHashCode(doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class ErrorInfo implements Serializable {
//
// private static final long serialVersionUID = 673514291953827696L;
//
// @Getter
// @Setter
// private String url;
//
// @Getter
// private List<ErrorItem> errors = new ArrayList<>();
//
// public ErrorInfo addError(String field, String message) {
// errors.add(new ErrorItem().setField(field).setMessage(message));
// return this;
// }
//
// public static ErrorInfo generateErrorInfoFromBindingResult(BindingResult errors) {
// ErrorInfo errorInfo = new ErrorInfo();
// errors.getFieldErrors()
// .forEach(fieldError -> errorInfo.addError(fieldError.getField(), fieldError.getDefaultMessage()));
//
// return errorInfo;
// }
// }
// Path: src/main/java/com/edwise/completespring/controllers/RestExceptionProcessor.java
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.exceptions.helpers.ErrorInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import javax.servlet.http.HttpServletRequest;
package com.edwise.completespring.controllers;
@ControllerAdvice
@Slf4j
public class RestExceptionProcessor {
private static final String FIELD_ID = "id";
| @ExceptionHandler(NotFoundException.class) |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/controllers/RestExceptionProcessor.java | // Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/helpers/ErrorInfo.java
// @Accessors(chain = true)
// @EqualsAndHashCode(doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class ErrorInfo implements Serializable {
//
// private static final long serialVersionUID = 673514291953827696L;
//
// @Getter
// @Setter
// private String url;
//
// @Getter
// private List<ErrorItem> errors = new ArrayList<>();
//
// public ErrorInfo addError(String field, String message) {
// errors.add(new ErrorItem().setField(field).setMessage(message));
// return this;
// }
//
// public static ErrorInfo generateErrorInfoFromBindingResult(BindingResult errors) {
// ErrorInfo errorInfo = new ErrorInfo();
// errors.getFieldErrors()
// .forEach(fieldError -> errorInfo.addError(fieldError.getField(), fieldError.getDefaultMessage()));
//
// return errorInfo;
// }
// }
| import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.exceptions.helpers.ErrorInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import javax.servlet.http.HttpServletRequest; | package com.edwise.completespring.controllers;
@ControllerAdvice
@Slf4j
public class RestExceptionProcessor {
private static final String FIELD_ID = "id";
@ExceptionHandler(NotFoundException.class)
@ResponseStatus(value = HttpStatus.NOT_FOUND)
@ResponseBody | // Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/helpers/ErrorInfo.java
// @Accessors(chain = true)
// @EqualsAndHashCode(doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class ErrorInfo implements Serializable {
//
// private static final long serialVersionUID = 673514291953827696L;
//
// @Getter
// @Setter
// private String url;
//
// @Getter
// private List<ErrorItem> errors = new ArrayList<>();
//
// public ErrorInfo addError(String field, String message) {
// errors.add(new ErrorItem().setField(field).setMessage(message));
// return this;
// }
//
// public static ErrorInfo generateErrorInfoFromBindingResult(BindingResult errors) {
// ErrorInfo errorInfo = new ErrorInfo();
// errors.getFieldErrors()
// .forEach(fieldError -> errorInfo.addError(fieldError.getField(), fieldError.getDefaultMessage()));
//
// return errorInfo;
// }
// }
// Path: src/main/java/com/edwise/completespring/controllers/RestExceptionProcessor.java
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.exceptions.helpers.ErrorInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import javax.servlet.http.HttpServletRequest;
package com.edwise.completespring.controllers;
@ControllerAdvice
@Slf4j
public class RestExceptionProcessor {
private static final String FIELD_ID = "id";
@ExceptionHandler(NotFoundException.class)
@ResponseStatus(value = HttpStatus.NOT_FOUND)
@ResponseBody | public ErrorInfo entityNotFound(HttpServletRequest req, NotFoundException ex) { |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/controllers/RestExceptionProcessor.java | // Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/helpers/ErrorInfo.java
// @Accessors(chain = true)
// @EqualsAndHashCode(doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class ErrorInfo implements Serializable {
//
// private static final long serialVersionUID = 673514291953827696L;
//
// @Getter
// @Setter
// private String url;
//
// @Getter
// private List<ErrorItem> errors = new ArrayList<>();
//
// public ErrorInfo addError(String field, String message) {
// errors.add(new ErrorItem().setField(field).setMessage(message));
// return this;
// }
//
// public static ErrorInfo generateErrorInfoFromBindingResult(BindingResult errors) {
// ErrorInfo errorInfo = new ErrorInfo();
// errors.getFieldErrors()
// .forEach(fieldError -> errorInfo.addError(fieldError.getField(), fieldError.getDefaultMessage()));
//
// return errorInfo;
// }
// }
| import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.exceptions.helpers.ErrorInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import javax.servlet.http.HttpServletRequest; | package com.edwise.completespring.controllers;
@ControllerAdvice
@Slf4j
public class RestExceptionProcessor {
private static final String FIELD_ID = "id";
@ExceptionHandler(NotFoundException.class)
@ResponseStatus(value = HttpStatus.NOT_FOUND)
@ResponseBody
public ErrorInfo entityNotFound(HttpServletRequest req, NotFoundException ex) {
String errorURL = req.getRequestURL().toString();
log.warn("Entity not found: {}", errorURL);
return new ErrorInfo()
.setUrl(errorURL)
.addError(FIELD_ID, ex.getMessage());
}
| // Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/helpers/ErrorInfo.java
// @Accessors(chain = true)
// @EqualsAndHashCode(doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class ErrorInfo implements Serializable {
//
// private static final long serialVersionUID = 673514291953827696L;
//
// @Getter
// @Setter
// private String url;
//
// @Getter
// private List<ErrorItem> errors = new ArrayList<>();
//
// public ErrorInfo addError(String field, String message) {
// errors.add(new ErrorItem().setField(field).setMessage(message));
// return this;
// }
//
// public static ErrorInfo generateErrorInfoFromBindingResult(BindingResult errors) {
// ErrorInfo errorInfo = new ErrorInfo();
// errors.getFieldErrors()
// .forEach(fieldError -> errorInfo.addError(fieldError.getField(), fieldError.getDefaultMessage()));
//
// return errorInfo;
// }
// }
// Path: src/main/java/com/edwise/completespring/controllers/RestExceptionProcessor.java
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.exceptions.helpers.ErrorInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import javax.servlet.http.HttpServletRequest;
package com.edwise.completespring.controllers;
@ControllerAdvice
@Slf4j
public class RestExceptionProcessor {
private static final String FIELD_ID = "id";
@ExceptionHandler(NotFoundException.class)
@ResponseStatus(value = HttpStatus.NOT_FOUND)
@ResponseBody
public ErrorInfo entityNotFound(HttpServletRequest req, NotFoundException ex) {
String errorURL = req.getRequestURL().toString();
log.warn("Entity not found: {}", errorURL);
return new ErrorInfo()
.setUrl(errorURL)
.addError(FIELD_ID, ex.getMessage());
}
| @ExceptionHandler(InvalidRequestException.class) |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/controllers/BookControllerTest.java | // Path: src/main/java/com/edwise/completespring/assemblers/BookResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class BookResource extends ResourceSupport {
// private Book book;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/BookResourceAssembler.java
// @Component
// public class BookResourceAssembler extends ResourceAssemblerSupport<Book, BookResource> {
//
// public BookResourceAssembler() {
// super(BookController.class, BookResource.class);
// }
//
// @Override
// protected BookResource instantiateResource(Book book) {
// BookResource bookResource = super.instantiateResource(book);
// bookResource.setBook(book);
//
// return bookResource;
// }
//
// public BookResource toResource(Book book) {
// return createResourceWithId(book.getId(), book);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
//
// Path: src/test/java/com/edwise/completespring/testutil/BookBuilder.java
// public class BookBuilder {
//
// private final Book book;
//
// public BookBuilder() {
// book = new Book();
// }
//
// public BookBuilder id(Long id) {
// book.setId(id);
// return this;
// }
//
// public BookBuilder title(String title) {
// book.setTitle(title);
// return this;
// }
//
// public BookBuilder authors(List<Author> authors) {
// book.setAuthors(authors);
// return this;
// }
//
// public BookBuilder isbn(String isbn) {
// book.setIsbn(isbn);
// return this;
// }
//
// public BookBuilder releaseDate(LocalDate releaseDate) {
// book.setReleaseDate(releaseDate);
// return this;
// }
//
// public BookBuilder publisher(Publisher publisher) {
// book.setPublisher(publisher);
// return this;
// }
//
// public Book build() {
// return book;
// }
// }
| import com.edwise.completespring.assemblers.BookResource;
import com.edwise.completespring.assemblers.BookResourceAssembler;
import com.edwise.completespring.entities.*;
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.services.BookService;
import com.edwise.completespring.testutil.BookBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*; | package com.edwise.completespring.controllers;
@RunWith(MockitoJUnitRunner.class)
public class BookControllerTest {
private static final long BOOK_ID_TEST1 = 1L;
private static final String BOOK_TITLE_TEST1 = "Lord of the Rings";
private static final String BOOK_TITLE_TEST2 = "Hamlet";
private static final long BOOK_ID_TEST2 = 1000L;
private static final LocalDate BOOK_RELEASEDATE_TEST1 = LocalDate.of(2013, 1, 26);
private static final LocalDate BOOK_RELEASEDATE_TEST2 = LocalDate.of(2011, 11, 16);
private static final String BOOK_ISBN_TEST1 = "11-333-12";
private static final String BOOK_ISBN_TEST2 = "11-666-77";
private static final String PUBLISHER_NAME_TEST1 = "Planeta";
private static final String PUBLISHER_NAME_TEST2 = "Gigamesh";
private static final String PUBLISHER_COUNTRY_TEST1 = "ES";
private static final String PUBLISHER_COUNTRY_TEST2 = "US";
private static final String AUTHOR_NAME_TEST1 = "J.R.R.";
private static final String AUTHOR_NAME_TEST2 = "William";
private static final String AUTHOR_SURNAME_TEST1 = "Tolkien";
private static final String AUTHOR_SURNAME_TEST2 = "Shakespeare";
private static final int ONE_TIME = 1;
@Mock | // Path: src/main/java/com/edwise/completespring/assemblers/BookResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class BookResource extends ResourceSupport {
// private Book book;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/BookResourceAssembler.java
// @Component
// public class BookResourceAssembler extends ResourceAssemblerSupport<Book, BookResource> {
//
// public BookResourceAssembler() {
// super(BookController.class, BookResource.class);
// }
//
// @Override
// protected BookResource instantiateResource(Book book) {
// BookResource bookResource = super.instantiateResource(book);
// bookResource.setBook(book);
//
// return bookResource;
// }
//
// public BookResource toResource(Book book) {
// return createResourceWithId(book.getId(), book);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
//
// Path: src/test/java/com/edwise/completespring/testutil/BookBuilder.java
// public class BookBuilder {
//
// private final Book book;
//
// public BookBuilder() {
// book = new Book();
// }
//
// public BookBuilder id(Long id) {
// book.setId(id);
// return this;
// }
//
// public BookBuilder title(String title) {
// book.setTitle(title);
// return this;
// }
//
// public BookBuilder authors(List<Author> authors) {
// book.setAuthors(authors);
// return this;
// }
//
// public BookBuilder isbn(String isbn) {
// book.setIsbn(isbn);
// return this;
// }
//
// public BookBuilder releaseDate(LocalDate releaseDate) {
// book.setReleaseDate(releaseDate);
// return this;
// }
//
// public BookBuilder publisher(Publisher publisher) {
// book.setPublisher(publisher);
// return this;
// }
//
// public Book build() {
// return book;
// }
// }
// Path: src/test/java/com/edwise/completespring/controllers/BookControllerTest.java
import com.edwise.completespring.assemblers.BookResource;
import com.edwise.completespring.assemblers.BookResourceAssembler;
import com.edwise.completespring.entities.*;
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.services.BookService;
import com.edwise.completespring.testutil.BookBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*;
package com.edwise.completespring.controllers;
@RunWith(MockitoJUnitRunner.class)
public class BookControllerTest {
private static final long BOOK_ID_TEST1 = 1L;
private static final String BOOK_TITLE_TEST1 = "Lord of the Rings";
private static final String BOOK_TITLE_TEST2 = "Hamlet";
private static final long BOOK_ID_TEST2 = 1000L;
private static final LocalDate BOOK_RELEASEDATE_TEST1 = LocalDate.of(2013, 1, 26);
private static final LocalDate BOOK_RELEASEDATE_TEST2 = LocalDate.of(2011, 11, 16);
private static final String BOOK_ISBN_TEST1 = "11-333-12";
private static final String BOOK_ISBN_TEST2 = "11-666-77";
private static final String PUBLISHER_NAME_TEST1 = "Planeta";
private static final String PUBLISHER_NAME_TEST2 = "Gigamesh";
private static final String PUBLISHER_COUNTRY_TEST1 = "ES";
private static final String PUBLISHER_COUNTRY_TEST2 = "US";
private static final String AUTHOR_NAME_TEST1 = "J.R.R.";
private static final String AUTHOR_NAME_TEST2 = "William";
private static final String AUTHOR_SURNAME_TEST1 = "Tolkien";
private static final String AUTHOR_SURNAME_TEST2 = "Shakespeare";
private static final int ONE_TIME = 1;
@Mock | private BookService bookService; |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/controllers/BookControllerTest.java | // Path: src/main/java/com/edwise/completespring/assemblers/BookResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class BookResource extends ResourceSupport {
// private Book book;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/BookResourceAssembler.java
// @Component
// public class BookResourceAssembler extends ResourceAssemblerSupport<Book, BookResource> {
//
// public BookResourceAssembler() {
// super(BookController.class, BookResource.class);
// }
//
// @Override
// protected BookResource instantiateResource(Book book) {
// BookResource bookResource = super.instantiateResource(book);
// bookResource.setBook(book);
//
// return bookResource;
// }
//
// public BookResource toResource(Book book) {
// return createResourceWithId(book.getId(), book);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
//
// Path: src/test/java/com/edwise/completespring/testutil/BookBuilder.java
// public class BookBuilder {
//
// private final Book book;
//
// public BookBuilder() {
// book = new Book();
// }
//
// public BookBuilder id(Long id) {
// book.setId(id);
// return this;
// }
//
// public BookBuilder title(String title) {
// book.setTitle(title);
// return this;
// }
//
// public BookBuilder authors(List<Author> authors) {
// book.setAuthors(authors);
// return this;
// }
//
// public BookBuilder isbn(String isbn) {
// book.setIsbn(isbn);
// return this;
// }
//
// public BookBuilder releaseDate(LocalDate releaseDate) {
// book.setReleaseDate(releaseDate);
// return this;
// }
//
// public BookBuilder publisher(Publisher publisher) {
// book.setPublisher(publisher);
// return this;
// }
//
// public Book build() {
// return book;
// }
// }
| import com.edwise.completespring.assemblers.BookResource;
import com.edwise.completespring.assemblers.BookResourceAssembler;
import com.edwise.completespring.entities.*;
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.services.BookService;
import com.edwise.completespring.testutil.BookBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*; | package com.edwise.completespring.controllers;
@RunWith(MockitoJUnitRunner.class)
public class BookControllerTest {
private static final long BOOK_ID_TEST1 = 1L;
private static final String BOOK_TITLE_TEST1 = "Lord of the Rings";
private static final String BOOK_TITLE_TEST2 = "Hamlet";
private static final long BOOK_ID_TEST2 = 1000L;
private static final LocalDate BOOK_RELEASEDATE_TEST1 = LocalDate.of(2013, 1, 26);
private static final LocalDate BOOK_RELEASEDATE_TEST2 = LocalDate.of(2011, 11, 16);
private static final String BOOK_ISBN_TEST1 = "11-333-12";
private static final String BOOK_ISBN_TEST2 = "11-666-77";
private static final String PUBLISHER_NAME_TEST1 = "Planeta";
private static final String PUBLISHER_NAME_TEST2 = "Gigamesh";
private static final String PUBLISHER_COUNTRY_TEST1 = "ES";
private static final String PUBLISHER_COUNTRY_TEST2 = "US";
private static final String AUTHOR_NAME_TEST1 = "J.R.R.";
private static final String AUTHOR_NAME_TEST2 = "William";
private static final String AUTHOR_SURNAME_TEST1 = "Tolkien";
private static final String AUTHOR_SURNAME_TEST2 = "Shakespeare";
private static final int ONE_TIME = 1;
@Mock
private BookService bookService;
@Mock
private BindingResult errors;
@Mock | // Path: src/main/java/com/edwise/completespring/assemblers/BookResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class BookResource extends ResourceSupport {
// private Book book;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/BookResourceAssembler.java
// @Component
// public class BookResourceAssembler extends ResourceAssemblerSupport<Book, BookResource> {
//
// public BookResourceAssembler() {
// super(BookController.class, BookResource.class);
// }
//
// @Override
// protected BookResource instantiateResource(Book book) {
// BookResource bookResource = super.instantiateResource(book);
// bookResource.setBook(book);
//
// return bookResource;
// }
//
// public BookResource toResource(Book book) {
// return createResourceWithId(book.getId(), book);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
//
// Path: src/test/java/com/edwise/completespring/testutil/BookBuilder.java
// public class BookBuilder {
//
// private final Book book;
//
// public BookBuilder() {
// book = new Book();
// }
//
// public BookBuilder id(Long id) {
// book.setId(id);
// return this;
// }
//
// public BookBuilder title(String title) {
// book.setTitle(title);
// return this;
// }
//
// public BookBuilder authors(List<Author> authors) {
// book.setAuthors(authors);
// return this;
// }
//
// public BookBuilder isbn(String isbn) {
// book.setIsbn(isbn);
// return this;
// }
//
// public BookBuilder releaseDate(LocalDate releaseDate) {
// book.setReleaseDate(releaseDate);
// return this;
// }
//
// public BookBuilder publisher(Publisher publisher) {
// book.setPublisher(publisher);
// return this;
// }
//
// public Book build() {
// return book;
// }
// }
// Path: src/test/java/com/edwise/completespring/controllers/BookControllerTest.java
import com.edwise.completespring.assemblers.BookResource;
import com.edwise.completespring.assemblers.BookResourceAssembler;
import com.edwise.completespring.entities.*;
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.services.BookService;
import com.edwise.completespring.testutil.BookBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*;
package com.edwise.completespring.controllers;
@RunWith(MockitoJUnitRunner.class)
public class BookControllerTest {
private static final long BOOK_ID_TEST1 = 1L;
private static final String BOOK_TITLE_TEST1 = "Lord of the Rings";
private static final String BOOK_TITLE_TEST2 = "Hamlet";
private static final long BOOK_ID_TEST2 = 1000L;
private static final LocalDate BOOK_RELEASEDATE_TEST1 = LocalDate.of(2013, 1, 26);
private static final LocalDate BOOK_RELEASEDATE_TEST2 = LocalDate.of(2011, 11, 16);
private static final String BOOK_ISBN_TEST1 = "11-333-12";
private static final String BOOK_ISBN_TEST2 = "11-666-77";
private static final String PUBLISHER_NAME_TEST1 = "Planeta";
private static final String PUBLISHER_NAME_TEST2 = "Gigamesh";
private static final String PUBLISHER_COUNTRY_TEST1 = "ES";
private static final String PUBLISHER_COUNTRY_TEST2 = "US";
private static final String AUTHOR_NAME_TEST1 = "J.R.R.";
private static final String AUTHOR_NAME_TEST2 = "William";
private static final String AUTHOR_SURNAME_TEST1 = "Tolkien";
private static final String AUTHOR_SURNAME_TEST2 = "Shakespeare";
private static final int ONE_TIME = 1;
@Mock
private BookService bookService;
@Mock
private BindingResult errors;
@Mock | private BookResourceAssembler bookResourceAssembler; |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/controllers/BookControllerTest.java | // Path: src/main/java/com/edwise/completespring/assemblers/BookResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class BookResource extends ResourceSupport {
// private Book book;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/BookResourceAssembler.java
// @Component
// public class BookResourceAssembler extends ResourceAssemblerSupport<Book, BookResource> {
//
// public BookResourceAssembler() {
// super(BookController.class, BookResource.class);
// }
//
// @Override
// protected BookResource instantiateResource(Book book) {
// BookResource bookResource = super.instantiateResource(book);
// bookResource.setBook(book);
//
// return bookResource;
// }
//
// public BookResource toResource(Book book) {
// return createResourceWithId(book.getId(), book);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
//
// Path: src/test/java/com/edwise/completespring/testutil/BookBuilder.java
// public class BookBuilder {
//
// private final Book book;
//
// public BookBuilder() {
// book = new Book();
// }
//
// public BookBuilder id(Long id) {
// book.setId(id);
// return this;
// }
//
// public BookBuilder title(String title) {
// book.setTitle(title);
// return this;
// }
//
// public BookBuilder authors(List<Author> authors) {
// book.setAuthors(authors);
// return this;
// }
//
// public BookBuilder isbn(String isbn) {
// book.setIsbn(isbn);
// return this;
// }
//
// public BookBuilder releaseDate(LocalDate releaseDate) {
// book.setReleaseDate(releaseDate);
// return this;
// }
//
// public BookBuilder publisher(Publisher publisher) {
// book.setPublisher(publisher);
// return this;
// }
//
// public Book build() {
// return book;
// }
// }
| import com.edwise.completespring.assemblers.BookResource;
import com.edwise.completespring.assemblers.BookResourceAssembler;
import com.edwise.completespring.entities.*;
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.services.BookService;
import com.edwise.completespring.testutil.BookBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*; | private static final String BOOK_ISBN_TEST2 = "11-666-77";
private static final String PUBLISHER_NAME_TEST1 = "Planeta";
private static final String PUBLISHER_NAME_TEST2 = "Gigamesh";
private static final String PUBLISHER_COUNTRY_TEST1 = "ES";
private static final String PUBLISHER_COUNTRY_TEST2 = "US";
private static final String AUTHOR_NAME_TEST1 = "J.R.R.";
private static final String AUTHOR_NAME_TEST2 = "William";
private static final String AUTHOR_SURNAME_TEST1 = "Tolkien";
private static final String AUTHOR_SURNAME_TEST2 = "Shakespeare";
private static final int ONE_TIME = 1;
@Mock
private BookService bookService;
@Mock
private BindingResult errors;
@Mock
private BookResourceAssembler bookResourceAssembler;
@InjectMocks
private BookController controller = new BookController();
@Before
public void setUp() {
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(new MockHttpServletRequest()));
}
@Test
public void testCreate() { | // Path: src/main/java/com/edwise/completespring/assemblers/BookResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class BookResource extends ResourceSupport {
// private Book book;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/BookResourceAssembler.java
// @Component
// public class BookResourceAssembler extends ResourceAssemblerSupport<Book, BookResource> {
//
// public BookResourceAssembler() {
// super(BookController.class, BookResource.class);
// }
//
// @Override
// protected BookResource instantiateResource(Book book) {
// BookResource bookResource = super.instantiateResource(book);
// bookResource.setBook(book);
//
// return bookResource;
// }
//
// public BookResource toResource(Book book) {
// return createResourceWithId(book.getId(), book);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
//
// Path: src/test/java/com/edwise/completespring/testutil/BookBuilder.java
// public class BookBuilder {
//
// private final Book book;
//
// public BookBuilder() {
// book = new Book();
// }
//
// public BookBuilder id(Long id) {
// book.setId(id);
// return this;
// }
//
// public BookBuilder title(String title) {
// book.setTitle(title);
// return this;
// }
//
// public BookBuilder authors(List<Author> authors) {
// book.setAuthors(authors);
// return this;
// }
//
// public BookBuilder isbn(String isbn) {
// book.setIsbn(isbn);
// return this;
// }
//
// public BookBuilder releaseDate(LocalDate releaseDate) {
// book.setReleaseDate(releaseDate);
// return this;
// }
//
// public BookBuilder publisher(Publisher publisher) {
// book.setPublisher(publisher);
// return this;
// }
//
// public Book build() {
// return book;
// }
// }
// Path: src/test/java/com/edwise/completespring/controllers/BookControllerTest.java
import com.edwise.completespring.assemblers.BookResource;
import com.edwise.completespring.assemblers.BookResourceAssembler;
import com.edwise.completespring.entities.*;
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.services.BookService;
import com.edwise.completespring.testutil.BookBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*;
private static final String BOOK_ISBN_TEST2 = "11-666-77";
private static final String PUBLISHER_NAME_TEST1 = "Planeta";
private static final String PUBLISHER_NAME_TEST2 = "Gigamesh";
private static final String PUBLISHER_COUNTRY_TEST1 = "ES";
private static final String PUBLISHER_COUNTRY_TEST2 = "US";
private static final String AUTHOR_NAME_TEST1 = "J.R.R.";
private static final String AUTHOR_NAME_TEST2 = "William";
private static final String AUTHOR_SURNAME_TEST1 = "Tolkien";
private static final String AUTHOR_SURNAME_TEST2 = "Shakespeare";
private static final int ONE_TIME = 1;
@Mock
private BookService bookService;
@Mock
private BindingResult errors;
@Mock
private BookResourceAssembler bookResourceAssembler;
@InjectMocks
private BookController controller = new BookController();
@Before
public void setUp() {
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(new MockHttpServletRequest()));
}
@Test
public void testCreate() { | Book bookReq = new BookBuilder() |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/controllers/BookControllerTest.java | // Path: src/main/java/com/edwise/completespring/assemblers/BookResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class BookResource extends ResourceSupport {
// private Book book;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/BookResourceAssembler.java
// @Component
// public class BookResourceAssembler extends ResourceAssemblerSupport<Book, BookResource> {
//
// public BookResourceAssembler() {
// super(BookController.class, BookResource.class);
// }
//
// @Override
// protected BookResource instantiateResource(Book book) {
// BookResource bookResource = super.instantiateResource(book);
// bookResource.setBook(book);
//
// return bookResource;
// }
//
// public BookResource toResource(Book book) {
// return createResourceWithId(book.getId(), book);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
//
// Path: src/test/java/com/edwise/completespring/testutil/BookBuilder.java
// public class BookBuilder {
//
// private final Book book;
//
// public BookBuilder() {
// book = new Book();
// }
//
// public BookBuilder id(Long id) {
// book.setId(id);
// return this;
// }
//
// public BookBuilder title(String title) {
// book.setTitle(title);
// return this;
// }
//
// public BookBuilder authors(List<Author> authors) {
// book.setAuthors(authors);
// return this;
// }
//
// public BookBuilder isbn(String isbn) {
// book.setIsbn(isbn);
// return this;
// }
//
// public BookBuilder releaseDate(LocalDate releaseDate) {
// book.setReleaseDate(releaseDate);
// return this;
// }
//
// public BookBuilder publisher(Publisher publisher) {
// book.setPublisher(publisher);
// return this;
// }
//
// public Book build() {
// return book;
// }
// }
| import com.edwise.completespring.assemblers.BookResource;
import com.edwise.completespring.assemblers.BookResourceAssembler;
import com.edwise.completespring.entities.*;
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.services.BookService;
import com.edwise.completespring.testutil.BookBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*; | private BookService bookService;
@Mock
private BindingResult errors;
@Mock
private BookResourceAssembler bookResourceAssembler;
@InjectMocks
private BookController controller = new BookController();
@Before
public void setUp() {
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(new MockHttpServletRequest()));
}
@Test
public void testCreate() {
Book bookReq = new BookBuilder()
.title(BOOK_TITLE_TEST1)
.authors(Collections.singletonList(new Author().setName(AUTHOR_NAME_TEST1).setSurname(AUTHOR_SURNAME_TEST1)))
.isbn(BOOK_ISBN_TEST1)
.releaseDate(BOOK_RELEASEDATE_TEST1)
.publisher(new Publisher().setName(PUBLISHER_NAME_TEST1).setCountry(PUBLISHER_COUNTRY_TEST1).setOnline(false))
.build();
Book bookResp = new Book().copyFrom(bookReq).setId(BOOK_ID_TEST1);
when(errors.hasErrors()).thenReturn(false);
when(bookService.create(bookReq)).thenReturn(bookResp);
when(bookResourceAssembler.toResource(any(Book.class))).thenReturn(createBookResourceWithLink(bookResp));
| // Path: src/main/java/com/edwise/completespring/assemblers/BookResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class BookResource extends ResourceSupport {
// private Book book;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/BookResourceAssembler.java
// @Component
// public class BookResourceAssembler extends ResourceAssemblerSupport<Book, BookResource> {
//
// public BookResourceAssembler() {
// super(BookController.class, BookResource.class);
// }
//
// @Override
// protected BookResource instantiateResource(Book book) {
// BookResource bookResource = super.instantiateResource(book);
// bookResource.setBook(book);
//
// return bookResource;
// }
//
// public BookResource toResource(Book book) {
// return createResourceWithId(book.getId(), book);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
//
// Path: src/test/java/com/edwise/completespring/testutil/BookBuilder.java
// public class BookBuilder {
//
// private final Book book;
//
// public BookBuilder() {
// book = new Book();
// }
//
// public BookBuilder id(Long id) {
// book.setId(id);
// return this;
// }
//
// public BookBuilder title(String title) {
// book.setTitle(title);
// return this;
// }
//
// public BookBuilder authors(List<Author> authors) {
// book.setAuthors(authors);
// return this;
// }
//
// public BookBuilder isbn(String isbn) {
// book.setIsbn(isbn);
// return this;
// }
//
// public BookBuilder releaseDate(LocalDate releaseDate) {
// book.setReleaseDate(releaseDate);
// return this;
// }
//
// public BookBuilder publisher(Publisher publisher) {
// book.setPublisher(publisher);
// return this;
// }
//
// public Book build() {
// return book;
// }
// }
// Path: src/test/java/com/edwise/completespring/controllers/BookControllerTest.java
import com.edwise.completespring.assemblers.BookResource;
import com.edwise.completespring.assemblers.BookResourceAssembler;
import com.edwise.completespring.entities.*;
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.services.BookService;
import com.edwise.completespring.testutil.BookBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*;
private BookService bookService;
@Mock
private BindingResult errors;
@Mock
private BookResourceAssembler bookResourceAssembler;
@InjectMocks
private BookController controller = new BookController();
@Before
public void setUp() {
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(new MockHttpServletRequest()));
}
@Test
public void testCreate() {
Book bookReq = new BookBuilder()
.title(BOOK_TITLE_TEST1)
.authors(Collections.singletonList(new Author().setName(AUTHOR_NAME_TEST1).setSurname(AUTHOR_SURNAME_TEST1)))
.isbn(BOOK_ISBN_TEST1)
.releaseDate(BOOK_RELEASEDATE_TEST1)
.publisher(new Publisher().setName(PUBLISHER_NAME_TEST1).setCountry(PUBLISHER_COUNTRY_TEST1).setOnline(false))
.build();
Book bookResp = new Book().copyFrom(bookReq).setId(BOOK_ID_TEST1);
when(errors.hasErrors()).thenReturn(false);
when(bookService.create(bookReq)).thenReturn(bookResp);
when(bookResourceAssembler.toResource(any(Book.class))).thenReturn(createBookResourceWithLink(bookResp));
| ResponseEntity<BookResource> result = controller.createBook(bookReq, errors); |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/controllers/BookControllerTest.java | // Path: src/main/java/com/edwise/completespring/assemblers/BookResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class BookResource extends ResourceSupport {
// private Book book;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/BookResourceAssembler.java
// @Component
// public class BookResourceAssembler extends ResourceAssemblerSupport<Book, BookResource> {
//
// public BookResourceAssembler() {
// super(BookController.class, BookResource.class);
// }
//
// @Override
// protected BookResource instantiateResource(Book book) {
// BookResource bookResource = super.instantiateResource(book);
// bookResource.setBook(book);
//
// return bookResource;
// }
//
// public BookResource toResource(Book book) {
// return createResourceWithId(book.getId(), book);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
//
// Path: src/test/java/com/edwise/completespring/testutil/BookBuilder.java
// public class BookBuilder {
//
// private final Book book;
//
// public BookBuilder() {
// book = new Book();
// }
//
// public BookBuilder id(Long id) {
// book.setId(id);
// return this;
// }
//
// public BookBuilder title(String title) {
// book.setTitle(title);
// return this;
// }
//
// public BookBuilder authors(List<Author> authors) {
// book.setAuthors(authors);
// return this;
// }
//
// public BookBuilder isbn(String isbn) {
// book.setIsbn(isbn);
// return this;
// }
//
// public BookBuilder releaseDate(LocalDate releaseDate) {
// book.setReleaseDate(releaseDate);
// return this;
// }
//
// public BookBuilder publisher(Publisher publisher) {
// book.setPublisher(publisher);
// return this;
// }
//
// public Book build() {
// return book;
// }
// }
| import com.edwise.completespring.assemblers.BookResource;
import com.edwise.completespring.assemblers.BookResourceAssembler;
import com.edwise.completespring.entities.*;
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.services.BookService;
import com.edwise.completespring.testutil.BookBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*; | public void testCreate() {
Book bookReq = new BookBuilder()
.title(BOOK_TITLE_TEST1)
.authors(Collections.singletonList(new Author().setName(AUTHOR_NAME_TEST1).setSurname(AUTHOR_SURNAME_TEST1)))
.isbn(BOOK_ISBN_TEST1)
.releaseDate(BOOK_RELEASEDATE_TEST1)
.publisher(new Publisher().setName(PUBLISHER_NAME_TEST1).setCountry(PUBLISHER_COUNTRY_TEST1).setOnline(false))
.build();
Book bookResp = new Book().copyFrom(bookReq).setId(BOOK_ID_TEST1);
when(errors.hasErrors()).thenReturn(false);
when(bookService.create(bookReq)).thenReturn(bookResp);
when(bookResourceAssembler.toResource(any(Book.class))).thenReturn(createBookResourceWithLink(bookResp));
ResponseEntity<BookResource> result = controller.createBook(bookReq, errors);
assertThat(result.getBody()).isNull();
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.CREATED);
assertThat(result.getHeaders().getLocation().toString()).contains("/api/books/" + BOOK_ID_TEST1);
verify(bookResourceAssembler, times(ONE_TIME)).toResource(bookResp);
verify(errors, times(ONE_TIME)).hasErrors();
verify(bookService, times(ONE_TIME)).create(bookReq);
}
@Test
public void testCreateInvalidRequest() {
Book bookReq = new Book();
when(errors.hasErrors()).thenReturn(true);
Throwable thrown = catchThrowable(() -> controller.createBook(bookReq, errors));
| // Path: src/main/java/com/edwise/completespring/assemblers/BookResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class BookResource extends ResourceSupport {
// private Book book;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/BookResourceAssembler.java
// @Component
// public class BookResourceAssembler extends ResourceAssemblerSupport<Book, BookResource> {
//
// public BookResourceAssembler() {
// super(BookController.class, BookResource.class);
// }
//
// @Override
// protected BookResource instantiateResource(Book book) {
// BookResource bookResource = super.instantiateResource(book);
// bookResource.setBook(book);
//
// return bookResource;
// }
//
// public BookResource toResource(Book book) {
// return createResourceWithId(book.getId(), book);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
//
// Path: src/test/java/com/edwise/completespring/testutil/BookBuilder.java
// public class BookBuilder {
//
// private final Book book;
//
// public BookBuilder() {
// book = new Book();
// }
//
// public BookBuilder id(Long id) {
// book.setId(id);
// return this;
// }
//
// public BookBuilder title(String title) {
// book.setTitle(title);
// return this;
// }
//
// public BookBuilder authors(List<Author> authors) {
// book.setAuthors(authors);
// return this;
// }
//
// public BookBuilder isbn(String isbn) {
// book.setIsbn(isbn);
// return this;
// }
//
// public BookBuilder releaseDate(LocalDate releaseDate) {
// book.setReleaseDate(releaseDate);
// return this;
// }
//
// public BookBuilder publisher(Publisher publisher) {
// book.setPublisher(publisher);
// return this;
// }
//
// public Book build() {
// return book;
// }
// }
// Path: src/test/java/com/edwise/completespring/controllers/BookControllerTest.java
import com.edwise.completespring.assemblers.BookResource;
import com.edwise.completespring.assemblers.BookResourceAssembler;
import com.edwise.completespring.entities.*;
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.services.BookService;
import com.edwise.completespring.testutil.BookBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*;
public void testCreate() {
Book bookReq = new BookBuilder()
.title(BOOK_TITLE_TEST1)
.authors(Collections.singletonList(new Author().setName(AUTHOR_NAME_TEST1).setSurname(AUTHOR_SURNAME_TEST1)))
.isbn(BOOK_ISBN_TEST1)
.releaseDate(BOOK_RELEASEDATE_TEST1)
.publisher(new Publisher().setName(PUBLISHER_NAME_TEST1).setCountry(PUBLISHER_COUNTRY_TEST1).setOnline(false))
.build();
Book bookResp = new Book().copyFrom(bookReq).setId(BOOK_ID_TEST1);
when(errors.hasErrors()).thenReturn(false);
when(bookService.create(bookReq)).thenReturn(bookResp);
when(bookResourceAssembler.toResource(any(Book.class))).thenReturn(createBookResourceWithLink(bookResp));
ResponseEntity<BookResource> result = controller.createBook(bookReq, errors);
assertThat(result.getBody()).isNull();
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.CREATED);
assertThat(result.getHeaders().getLocation().toString()).contains("/api/books/" + BOOK_ID_TEST1);
verify(bookResourceAssembler, times(ONE_TIME)).toResource(bookResp);
verify(errors, times(ONE_TIME)).hasErrors();
verify(bookService, times(ONE_TIME)).create(bookReq);
}
@Test
public void testCreateInvalidRequest() {
Book bookReq = new Book();
when(errors.hasErrors()).thenReturn(true);
Throwable thrown = catchThrowable(() -> controller.createBook(bookReq, errors));
| assertThat(thrown).isInstanceOf(InvalidRequestException.class); |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/controllers/BookControllerTest.java | // Path: src/main/java/com/edwise/completespring/assemblers/BookResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class BookResource extends ResourceSupport {
// private Book book;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/BookResourceAssembler.java
// @Component
// public class BookResourceAssembler extends ResourceAssemblerSupport<Book, BookResource> {
//
// public BookResourceAssembler() {
// super(BookController.class, BookResource.class);
// }
//
// @Override
// protected BookResource instantiateResource(Book book) {
// BookResource bookResource = super.instantiateResource(book);
// bookResource.setBook(book);
//
// return bookResource;
// }
//
// public BookResource toResource(Book book) {
// return createResourceWithId(book.getId(), book);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
//
// Path: src/test/java/com/edwise/completespring/testutil/BookBuilder.java
// public class BookBuilder {
//
// private final Book book;
//
// public BookBuilder() {
// book = new Book();
// }
//
// public BookBuilder id(Long id) {
// book.setId(id);
// return this;
// }
//
// public BookBuilder title(String title) {
// book.setTitle(title);
// return this;
// }
//
// public BookBuilder authors(List<Author> authors) {
// book.setAuthors(authors);
// return this;
// }
//
// public BookBuilder isbn(String isbn) {
// book.setIsbn(isbn);
// return this;
// }
//
// public BookBuilder releaseDate(LocalDate releaseDate) {
// book.setReleaseDate(releaseDate);
// return this;
// }
//
// public BookBuilder publisher(Publisher publisher) {
// book.setPublisher(publisher);
// return this;
// }
//
// public Book build() {
// return book;
// }
// }
| import com.edwise.completespring.assemblers.BookResource;
import com.edwise.completespring.assemblers.BookResourceAssembler;
import com.edwise.completespring.entities.*;
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.services.BookService;
import com.edwise.completespring.testutil.BookBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*; |
Throwable thrown = catchThrowable(() -> controller.updateBook(BOOK_ID_TEST1, bookReq, errors));
assertThat(thrown).isInstanceOf(InvalidRequestException.class);
}
@Test
public void testGet() {
Book bookReq = new BookBuilder()
.id(BOOK_ID_TEST1)
.title(BOOK_TITLE_TEST1)
.authors(Collections.singletonList(new Author().setName(AUTHOR_NAME_TEST1).setSurname(AUTHOR_SURNAME_TEST1)))
.isbn(BOOK_ISBN_TEST1)
.releaseDate(BOOK_RELEASEDATE_TEST1)
.publisher(new Publisher().setName(PUBLISHER_NAME_TEST1).setCountry(PUBLISHER_COUNTRY_TEST1).setOnline(false))
.build();
when(bookService.findOne(BOOK_ID_TEST1)).thenReturn(bookReq);
when(bookResourceAssembler.toResource(any(Book.class))).thenReturn(new BookResource().setBook(bookReq));
ResponseEntity<BookResource> result = controller.getBook(BOOK_ID_TEST1);
assertThat(result.getBody()).isNotNull();
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
verify(bookService, times(ONE_TIME)).findOne(BOOK_ID_TEST1);
verify(bookResourceAssembler, times(ONE_TIME)).toResource(bookReq);
}
@Test
public void testGetNotFound() { | // Path: src/main/java/com/edwise/completespring/assemblers/BookResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class BookResource extends ResourceSupport {
// private Book book;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/BookResourceAssembler.java
// @Component
// public class BookResourceAssembler extends ResourceAssemblerSupport<Book, BookResource> {
//
// public BookResourceAssembler() {
// super(BookController.class, BookResource.class);
// }
//
// @Override
// protected BookResource instantiateResource(Book book) {
// BookResource bookResource = super.instantiateResource(book);
// bookResource.setBook(book);
//
// return bookResource;
// }
//
// public BookResource toResource(Book book) {
// return createResourceWithId(book.getId(), book);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/services/BookService.java
// public interface BookService extends Service<Book, Long> {
//
// List<Book> findByTitle(String title);
//
// List<Book> findByReleaseDate(LocalDate releaseDate);
//
// Book create(Book book);
// }
//
// Path: src/test/java/com/edwise/completespring/testutil/BookBuilder.java
// public class BookBuilder {
//
// private final Book book;
//
// public BookBuilder() {
// book = new Book();
// }
//
// public BookBuilder id(Long id) {
// book.setId(id);
// return this;
// }
//
// public BookBuilder title(String title) {
// book.setTitle(title);
// return this;
// }
//
// public BookBuilder authors(List<Author> authors) {
// book.setAuthors(authors);
// return this;
// }
//
// public BookBuilder isbn(String isbn) {
// book.setIsbn(isbn);
// return this;
// }
//
// public BookBuilder releaseDate(LocalDate releaseDate) {
// book.setReleaseDate(releaseDate);
// return this;
// }
//
// public BookBuilder publisher(Publisher publisher) {
// book.setPublisher(publisher);
// return this;
// }
//
// public Book build() {
// return book;
// }
// }
// Path: src/test/java/com/edwise/completespring/controllers/BookControllerTest.java
import com.edwise.completespring.assemblers.BookResource;
import com.edwise.completespring.assemblers.BookResourceAssembler;
import com.edwise.completespring.entities.*;
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.services.BookService;
import com.edwise.completespring.testutil.BookBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.*;
Throwable thrown = catchThrowable(() -> controller.updateBook(BOOK_ID_TEST1, bookReq, errors));
assertThat(thrown).isInstanceOf(InvalidRequestException.class);
}
@Test
public void testGet() {
Book bookReq = new BookBuilder()
.id(BOOK_ID_TEST1)
.title(BOOK_TITLE_TEST1)
.authors(Collections.singletonList(new Author().setName(AUTHOR_NAME_TEST1).setSurname(AUTHOR_SURNAME_TEST1)))
.isbn(BOOK_ISBN_TEST1)
.releaseDate(BOOK_RELEASEDATE_TEST1)
.publisher(new Publisher().setName(PUBLISHER_NAME_TEST1).setCountry(PUBLISHER_COUNTRY_TEST1).setOnline(false))
.build();
when(bookService.findOne(BOOK_ID_TEST1)).thenReturn(bookReq);
when(bookResourceAssembler.toResource(any(Book.class))).thenReturn(new BookResource().setBook(bookReq));
ResponseEntity<BookResource> result = controller.getBook(BOOK_ID_TEST1);
assertThat(result.getBody()).isNotNull();
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
verify(bookService, times(ONE_TIME)).findOne(BOOK_ID_TEST1);
verify(bookResourceAssembler, times(ONE_TIME)).toResource(bookReq);
}
@Test
public void testGetNotFound() { | when(bookService.findOne(BOOK_ID_TEST2)).thenThrow(new NotFoundException("Book not exist")); |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/controllers/RestExceptionProcessorTest.java | // Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/helpers/ErrorInfo.java
// @Accessors(chain = true)
// @EqualsAndHashCode(doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class ErrorInfo implements Serializable {
//
// private static final long serialVersionUID = 673514291953827696L;
//
// @Getter
// @Setter
// private String url;
//
// @Getter
// private List<ErrorItem> errors = new ArrayList<>();
//
// public ErrorInfo addError(String field, String message) {
// errors.add(new ErrorItem().setField(field).setMessage(message));
// return this;
// }
//
// public static ErrorInfo generateErrorInfoFromBindingResult(BindingResult errors) {
// ErrorInfo errorInfo = new ErrorInfo();
// errors.getFieldErrors()
// .forEach(fieldError -> errorInfo.addError(fieldError.getField(), fieldError.getDefaultMessage()));
//
// return errorInfo;
// }
// }
| import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.exceptions.helpers.ErrorInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when; | package com.edwise.completespring.controllers;
@RunWith(MockitoJUnitRunner.class)
public class RestExceptionProcessorTest {
private static final int ONE_ITEM = 1;
private static final int TWO_ITEMS = 2;
private static final String FIELD_ERROR_OBJECT_TEST1 = "Book";
private static final String FIELD_ERROR_FIELD_TEST1 = "title";
private static final String FIELD_ERROR_FIELD_TEST2 = "isbn";
private static final String FIELD_ERROR_MESSAGE_TEST1 = "No puede ser nulo";
private static final String FIELD_ERROR_MESSAGE_TEST2 = "No puede ser vacio";
private static final String EXCEPTION_MESSAGE_TEST1 = "No existe la entidad";
private RestExceptionProcessor restExceptionProcessor;
private MockHttpServletRequest request;
@Mock
private BindingResult errors;
@Before
public void setUp() {
this.request = new MockHttpServletRequest();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.request));
this.restExceptionProcessor = new RestExceptionProcessor();
}
@Test
public void testEntityNotFound() { | // Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/helpers/ErrorInfo.java
// @Accessors(chain = true)
// @EqualsAndHashCode(doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class ErrorInfo implements Serializable {
//
// private static final long serialVersionUID = 673514291953827696L;
//
// @Getter
// @Setter
// private String url;
//
// @Getter
// private List<ErrorItem> errors = new ArrayList<>();
//
// public ErrorInfo addError(String field, String message) {
// errors.add(new ErrorItem().setField(field).setMessage(message));
// return this;
// }
//
// public static ErrorInfo generateErrorInfoFromBindingResult(BindingResult errors) {
// ErrorInfo errorInfo = new ErrorInfo();
// errors.getFieldErrors()
// .forEach(fieldError -> errorInfo.addError(fieldError.getField(), fieldError.getDefaultMessage()));
//
// return errorInfo;
// }
// }
// Path: src/test/java/com/edwise/completespring/controllers/RestExceptionProcessorTest.java
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.exceptions.helpers.ErrorInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
package com.edwise.completespring.controllers;
@RunWith(MockitoJUnitRunner.class)
public class RestExceptionProcessorTest {
private static final int ONE_ITEM = 1;
private static final int TWO_ITEMS = 2;
private static final String FIELD_ERROR_OBJECT_TEST1 = "Book";
private static final String FIELD_ERROR_FIELD_TEST1 = "title";
private static final String FIELD_ERROR_FIELD_TEST2 = "isbn";
private static final String FIELD_ERROR_MESSAGE_TEST1 = "No puede ser nulo";
private static final String FIELD_ERROR_MESSAGE_TEST2 = "No puede ser vacio";
private static final String EXCEPTION_MESSAGE_TEST1 = "No existe la entidad";
private RestExceptionProcessor restExceptionProcessor;
private MockHttpServletRequest request;
@Mock
private BindingResult errors;
@Before
public void setUp() {
this.request = new MockHttpServletRequest();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.request));
this.restExceptionProcessor = new RestExceptionProcessor();
}
@Test
public void testEntityNotFound() { | NotFoundException exception = new NotFoundException(EXCEPTION_MESSAGE_TEST1); |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/controllers/RestExceptionProcessorTest.java | // Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/helpers/ErrorInfo.java
// @Accessors(chain = true)
// @EqualsAndHashCode(doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class ErrorInfo implements Serializable {
//
// private static final long serialVersionUID = 673514291953827696L;
//
// @Getter
// @Setter
// private String url;
//
// @Getter
// private List<ErrorItem> errors = new ArrayList<>();
//
// public ErrorInfo addError(String field, String message) {
// errors.add(new ErrorItem().setField(field).setMessage(message));
// return this;
// }
//
// public static ErrorInfo generateErrorInfoFromBindingResult(BindingResult errors) {
// ErrorInfo errorInfo = new ErrorInfo();
// errors.getFieldErrors()
// .forEach(fieldError -> errorInfo.addError(fieldError.getField(), fieldError.getDefaultMessage()));
//
// return errorInfo;
// }
// }
| import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.exceptions.helpers.ErrorInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when; | package com.edwise.completespring.controllers;
@RunWith(MockitoJUnitRunner.class)
public class RestExceptionProcessorTest {
private static final int ONE_ITEM = 1;
private static final int TWO_ITEMS = 2;
private static final String FIELD_ERROR_OBJECT_TEST1 = "Book";
private static final String FIELD_ERROR_FIELD_TEST1 = "title";
private static final String FIELD_ERROR_FIELD_TEST2 = "isbn";
private static final String FIELD_ERROR_MESSAGE_TEST1 = "No puede ser nulo";
private static final String FIELD_ERROR_MESSAGE_TEST2 = "No puede ser vacio";
private static final String EXCEPTION_MESSAGE_TEST1 = "No existe la entidad";
private RestExceptionProcessor restExceptionProcessor;
private MockHttpServletRequest request;
@Mock
private BindingResult errors;
@Before
public void setUp() {
this.request = new MockHttpServletRequest();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.request));
this.restExceptionProcessor = new RestExceptionProcessor();
}
@Test
public void testEntityNotFound() {
NotFoundException exception = new NotFoundException(EXCEPTION_MESSAGE_TEST1);
| // Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/helpers/ErrorInfo.java
// @Accessors(chain = true)
// @EqualsAndHashCode(doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class ErrorInfo implements Serializable {
//
// private static final long serialVersionUID = 673514291953827696L;
//
// @Getter
// @Setter
// private String url;
//
// @Getter
// private List<ErrorItem> errors = new ArrayList<>();
//
// public ErrorInfo addError(String field, String message) {
// errors.add(new ErrorItem().setField(field).setMessage(message));
// return this;
// }
//
// public static ErrorInfo generateErrorInfoFromBindingResult(BindingResult errors) {
// ErrorInfo errorInfo = new ErrorInfo();
// errors.getFieldErrors()
// .forEach(fieldError -> errorInfo.addError(fieldError.getField(), fieldError.getDefaultMessage()));
//
// return errorInfo;
// }
// }
// Path: src/test/java/com/edwise/completespring/controllers/RestExceptionProcessorTest.java
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.exceptions.helpers.ErrorInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
package com.edwise.completespring.controllers;
@RunWith(MockitoJUnitRunner.class)
public class RestExceptionProcessorTest {
private static final int ONE_ITEM = 1;
private static final int TWO_ITEMS = 2;
private static final String FIELD_ERROR_OBJECT_TEST1 = "Book";
private static final String FIELD_ERROR_FIELD_TEST1 = "title";
private static final String FIELD_ERROR_FIELD_TEST2 = "isbn";
private static final String FIELD_ERROR_MESSAGE_TEST1 = "No puede ser nulo";
private static final String FIELD_ERROR_MESSAGE_TEST2 = "No puede ser vacio";
private static final String EXCEPTION_MESSAGE_TEST1 = "No existe la entidad";
private RestExceptionProcessor restExceptionProcessor;
private MockHttpServletRequest request;
@Mock
private BindingResult errors;
@Before
public void setUp() {
this.request = new MockHttpServletRequest();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.request));
this.restExceptionProcessor = new RestExceptionProcessor();
}
@Test
public void testEntityNotFound() {
NotFoundException exception = new NotFoundException(EXCEPTION_MESSAGE_TEST1);
| ErrorInfo errorInfo = restExceptionProcessor.entityNotFound(request, exception); |
edwise/complete-spring-project | src/test/java/com/edwise/completespring/controllers/RestExceptionProcessorTest.java | // Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/helpers/ErrorInfo.java
// @Accessors(chain = true)
// @EqualsAndHashCode(doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class ErrorInfo implements Serializable {
//
// private static final long serialVersionUID = 673514291953827696L;
//
// @Getter
// @Setter
// private String url;
//
// @Getter
// private List<ErrorItem> errors = new ArrayList<>();
//
// public ErrorInfo addError(String field, String message) {
// errors.add(new ErrorItem().setField(field).setMessage(message));
// return this;
// }
//
// public static ErrorInfo generateErrorInfoFromBindingResult(BindingResult errors) {
// ErrorInfo errorInfo = new ErrorInfo();
// errors.getFieldErrors()
// .forEach(fieldError -> errorInfo.addError(fieldError.getField(), fieldError.getDefaultMessage()));
//
// return errorInfo;
// }
// }
| import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.exceptions.helpers.ErrorInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when; | private static final String EXCEPTION_MESSAGE_TEST1 = "No existe la entidad";
private RestExceptionProcessor restExceptionProcessor;
private MockHttpServletRequest request;
@Mock
private BindingResult errors;
@Before
public void setUp() {
this.request = new MockHttpServletRequest();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.request));
this.restExceptionProcessor = new RestExceptionProcessor();
}
@Test
public void testEntityNotFound() {
NotFoundException exception = new NotFoundException(EXCEPTION_MESSAGE_TEST1);
ErrorInfo errorInfo = restExceptionProcessor.entityNotFound(request, exception);
assertThat(errorInfo).isNotNull();
assertThat(errorInfo.getUrl()).isEqualTo(request.getRequestURL().toString());
assertThat(errorInfo.getErrors()).hasSize(ONE_ITEM);
}
@Test
public void testInvalidPostData() {
when(errors.getFieldErrors()).thenReturn(createMockListFieldErrors()); | // Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String msg) {
// super(msg);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/helpers/ErrorInfo.java
// @Accessors(chain = true)
// @EqualsAndHashCode(doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class ErrorInfo implements Serializable {
//
// private static final long serialVersionUID = 673514291953827696L;
//
// @Getter
// @Setter
// private String url;
//
// @Getter
// private List<ErrorItem> errors = new ArrayList<>();
//
// public ErrorInfo addError(String field, String message) {
// errors.add(new ErrorItem().setField(field).setMessage(message));
// return this;
// }
//
// public static ErrorInfo generateErrorInfoFromBindingResult(BindingResult errors) {
// ErrorInfo errorInfo = new ErrorInfo();
// errors.getFieldErrors()
// .forEach(fieldError -> errorInfo.addError(fieldError.getField(), fieldError.getDefaultMessage()));
//
// return errorInfo;
// }
// }
// Path: src/test/java/com/edwise/completespring/controllers/RestExceptionProcessorTest.java
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.exceptions.helpers.ErrorInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
private static final String EXCEPTION_MESSAGE_TEST1 = "No existe la entidad";
private RestExceptionProcessor restExceptionProcessor;
private MockHttpServletRequest request;
@Mock
private BindingResult errors;
@Before
public void setUp() {
this.request = new MockHttpServletRequest();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.request));
this.restExceptionProcessor = new RestExceptionProcessor();
}
@Test
public void testEntityNotFound() {
NotFoundException exception = new NotFoundException(EXCEPTION_MESSAGE_TEST1);
ErrorInfo errorInfo = restExceptionProcessor.entityNotFound(request, exception);
assertThat(errorInfo).isNotNull();
assertThat(errorInfo.getUrl()).isEqualTo(request.getRequestURL().toString());
assertThat(errorInfo.getErrors()).hasSize(ONE_ITEM);
}
@Test
public void testInvalidPostData() {
when(errors.getFieldErrors()).thenReturn(createMockListFieldErrors()); | InvalidRequestException exception = new InvalidRequestException(errors); |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/controllers/FooController.java | // Path: src/main/java/com/edwise/completespring/assemblers/FooResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class FooResource extends ResourceSupport {
// private Foo foo;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/FooResourceAssembler.java
// @Component
// public class FooResourceAssembler extends ResourceAssemblerSupport<Foo, FooResource> {
//
// public FooResourceAssembler() {
// super(FooController.class, FooResource.class);
// }
//
// @Override
// protected FooResource instantiateResource(Foo foo) {
// FooResource fooResource = super.instantiateResource(foo);
// fooResource.setFoo(foo);
//
// return fooResource;
// }
//
// public FooResource toResource(Foo foo) {
// return this.createResourceWithId(foo.getId(), foo);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/Foo.java
// @ApiModel(value = "Foo entity", description = "Complete info of a entity foo")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Foo {
//
// @ApiModelProperty(value = "Sample Id Attribute", required = true)
// private Long id;
//
// @ApiModelProperty(value = "Sample Text Attribute", required = true)
// @NotNull
// private String sampleTextAttribute;
//
// @ApiModelProperty(value = "Sample Local Date Attribute", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate sampleLocalDateAttribute;
//
// public Foo copyFrom(Foo other) {
// this.sampleTextAttribute = other.sampleTextAttribute;
// this.sampleLocalDateAttribute = other.sampleLocalDateAttribute;
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
| import com.edwise.completespring.assemblers.FooResource;
import com.edwise.completespring.assemblers.FooResourceAssembler;
import com.edwise.completespring.entities.Foo;
import com.edwise.completespring.exceptions.InvalidRequestException;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.net.URI;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List; | package com.edwise.completespring.controllers;
@RestController
@RequestMapping(value = "/api/foos/")
@Api(value = "foos", description = "Foo API", produces = "application/json")
@Slf4j
public class FooController {
private static final int RESPONSE_CODE_OK = 200;
private static final int RESPONSE_CODE_CREATED = 201;
private static final int RESPONSE_CODE_NO_RESPONSE = 204;
private static final String TEST_ATTRIBUTE_1 = "AttText1";
@Autowired | // Path: src/main/java/com/edwise/completespring/assemblers/FooResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class FooResource extends ResourceSupport {
// private Foo foo;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/FooResourceAssembler.java
// @Component
// public class FooResourceAssembler extends ResourceAssemblerSupport<Foo, FooResource> {
//
// public FooResourceAssembler() {
// super(FooController.class, FooResource.class);
// }
//
// @Override
// protected FooResource instantiateResource(Foo foo) {
// FooResource fooResource = super.instantiateResource(foo);
// fooResource.setFoo(foo);
//
// return fooResource;
// }
//
// public FooResource toResource(Foo foo) {
// return this.createResourceWithId(foo.getId(), foo);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/Foo.java
// @ApiModel(value = "Foo entity", description = "Complete info of a entity foo")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Foo {
//
// @ApiModelProperty(value = "Sample Id Attribute", required = true)
// private Long id;
//
// @ApiModelProperty(value = "Sample Text Attribute", required = true)
// @NotNull
// private String sampleTextAttribute;
//
// @ApiModelProperty(value = "Sample Local Date Attribute", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate sampleLocalDateAttribute;
//
// public Foo copyFrom(Foo other) {
// this.sampleTextAttribute = other.sampleTextAttribute;
// this.sampleLocalDateAttribute = other.sampleLocalDateAttribute;
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
// Path: src/main/java/com/edwise/completespring/controllers/FooController.java
import com.edwise.completespring.assemblers.FooResource;
import com.edwise.completespring.assemblers.FooResourceAssembler;
import com.edwise.completespring.entities.Foo;
import com.edwise.completespring.exceptions.InvalidRequestException;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.net.URI;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
package com.edwise.completespring.controllers;
@RestController
@RequestMapping(value = "/api/foos/")
@Api(value = "foos", description = "Foo API", produces = "application/json")
@Slf4j
public class FooController {
private static final int RESPONSE_CODE_OK = 200;
private static final int RESPONSE_CODE_CREATED = 201;
private static final int RESPONSE_CODE_NO_RESPONSE = 204;
private static final String TEST_ATTRIBUTE_1 = "AttText1";
@Autowired | private FooResourceAssembler fooResourceAssembler; |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/controllers/FooController.java | // Path: src/main/java/com/edwise/completespring/assemblers/FooResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class FooResource extends ResourceSupport {
// private Foo foo;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/FooResourceAssembler.java
// @Component
// public class FooResourceAssembler extends ResourceAssemblerSupport<Foo, FooResource> {
//
// public FooResourceAssembler() {
// super(FooController.class, FooResource.class);
// }
//
// @Override
// protected FooResource instantiateResource(Foo foo) {
// FooResource fooResource = super.instantiateResource(foo);
// fooResource.setFoo(foo);
//
// return fooResource;
// }
//
// public FooResource toResource(Foo foo) {
// return this.createResourceWithId(foo.getId(), foo);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/Foo.java
// @ApiModel(value = "Foo entity", description = "Complete info of a entity foo")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Foo {
//
// @ApiModelProperty(value = "Sample Id Attribute", required = true)
// private Long id;
//
// @ApiModelProperty(value = "Sample Text Attribute", required = true)
// @NotNull
// private String sampleTextAttribute;
//
// @ApiModelProperty(value = "Sample Local Date Attribute", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate sampleLocalDateAttribute;
//
// public Foo copyFrom(Foo other) {
// this.sampleTextAttribute = other.sampleTextAttribute;
// this.sampleLocalDateAttribute = other.sampleLocalDateAttribute;
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
| import com.edwise.completespring.assemblers.FooResource;
import com.edwise.completespring.assemblers.FooResourceAssembler;
import com.edwise.completespring.entities.Foo;
import com.edwise.completespring.exceptions.InvalidRequestException;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.net.URI;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List; | package com.edwise.completespring.controllers;
@RestController
@RequestMapping(value = "/api/foos/")
@Api(value = "foos", description = "Foo API", produces = "application/json")
@Slf4j
public class FooController {
private static final int RESPONSE_CODE_OK = 200;
private static final int RESPONSE_CODE_CREATED = 201;
private static final int RESPONSE_CODE_NO_RESPONSE = 204;
private static final String TEST_ATTRIBUTE_1 = "AttText1";
@Autowired
private FooResourceAssembler fooResourceAssembler;
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get Foos", notes = "Returns all foos")
@ApiResponses({ | // Path: src/main/java/com/edwise/completespring/assemblers/FooResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class FooResource extends ResourceSupport {
// private Foo foo;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/FooResourceAssembler.java
// @Component
// public class FooResourceAssembler extends ResourceAssemblerSupport<Foo, FooResource> {
//
// public FooResourceAssembler() {
// super(FooController.class, FooResource.class);
// }
//
// @Override
// protected FooResource instantiateResource(Foo foo) {
// FooResource fooResource = super.instantiateResource(foo);
// fooResource.setFoo(foo);
//
// return fooResource;
// }
//
// public FooResource toResource(Foo foo) {
// return this.createResourceWithId(foo.getId(), foo);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/Foo.java
// @ApiModel(value = "Foo entity", description = "Complete info of a entity foo")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Foo {
//
// @ApiModelProperty(value = "Sample Id Attribute", required = true)
// private Long id;
//
// @ApiModelProperty(value = "Sample Text Attribute", required = true)
// @NotNull
// private String sampleTextAttribute;
//
// @ApiModelProperty(value = "Sample Local Date Attribute", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate sampleLocalDateAttribute;
//
// public Foo copyFrom(Foo other) {
// this.sampleTextAttribute = other.sampleTextAttribute;
// this.sampleLocalDateAttribute = other.sampleLocalDateAttribute;
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
// Path: src/main/java/com/edwise/completespring/controllers/FooController.java
import com.edwise.completespring.assemblers.FooResource;
import com.edwise.completespring.assemblers.FooResourceAssembler;
import com.edwise.completespring.entities.Foo;
import com.edwise.completespring.exceptions.InvalidRequestException;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.net.URI;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
package com.edwise.completespring.controllers;
@RestController
@RequestMapping(value = "/api/foos/")
@Api(value = "foos", description = "Foo API", produces = "application/json")
@Slf4j
public class FooController {
private static final int RESPONSE_CODE_OK = 200;
private static final int RESPONSE_CODE_CREATED = 201;
private static final int RESPONSE_CODE_NO_RESPONSE = 204;
private static final String TEST_ATTRIBUTE_1 = "AttText1";
@Autowired
private FooResourceAssembler fooResourceAssembler;
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get Foos", notes = "Returns all foos")
@ApiResponses({ | @ApiResponse(code = RESPONSE_CODE_OK, response = FooResource.class, message = "Exits one foo at least") |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/controllers/FooController.java | // Path: src/main/java/com/edwise/completespring/assemblers/FooResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class FooResource extends ResourceSupport {
// private Foo foo;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/FooResourceAssembler.java
// @Component
// public class FooResourceAssembler extends ResourceAssemblerSupport<Foo, FooResource> {
//
// public FooResourceAssembler() {
// super(FooController.class, FooResource.class);
// }
//
// @Override
// protected FooResource instantiateResource(Foo foo) {
// FooResource fooResource = super.instantiateResource(foo);
// fooResource.setFoo(foo);
//
// return fooResource;
// }
//
// public FooResource toResource(Foo foo) {
// return this.createResourceWithId(foo.getId(), foo);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/Foo.java
// @ApiModel(value = "Foo entity", description = "Complete info of a entity foo")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Foo {
//
// @ApiModelProperty(value = "Sample Id Attribute", required = true)
// private Long id;
//
// @ApiModelProperty(value = "Sample Text Attribute", required = true)
// @NotNull
// private String sampleTextAttribute;
//
// @ApiModelProperty(value = "Sample Local Date Attribute", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate sampleLocalDateAttribute;
//
// public Foo copyFrom(Foo other) {
// this.sampleTextAttribute = other.sampleTextAttribute;
// this.sampleLocalDateAttribute = other.sampleLocalDateAttribute;
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
| import com.edwise.completespring.assemblers.FooResource;
import com.edwise.completespring.assemblers.FooResourceAssembler;
import com.edwise.completespring.entities.Foo;
import com.edwise.completespring.exceptions.InvalidRequestException;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.net.URI;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List; | package com.edwise.completespring.controllers;
@RestController
@RequestMapping(value = "/api/foos/")
@Api(value = "foos", description = "Foo API", produces = "application/json")
@Slf4j
public class FooController {
private static final int RESPONSE_CODE_OK = 200;
private static final int RESPONSE_CODE_CREATED = 201;
private static final int RESPONSE_CODE_NO_RESPONSE = 204;
private static final String TEST_ATTRIBUTE_1 = "AttText1";
@Autowired
private FooResourceAssembler fooResourceAssembler;
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get Foos", notes = "Returns all foos")
@ApiResponses({
@ApiResponse(code = RESPONSE_CODE_OK, response = FooResource.class, message = "Exits one foo at least")
})
public ResponseEntity<List<FooResource>> getAll() { | // Path: src/main/java/com/edwise/completespring/assemblers/FooResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class FooResource extends ResourceSupport {
// private Foo foo;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/FooResourceAssembler.java
// @Component
// public class FooResourceAssembler extends ResourceAssemblerSupport<Foo, FooResource> {
//
// public FooResourceAssembler() {
// super(FooController.class, FooResource.class);
// }
//
// @Override
// protected FooResource instantiateResource(Foo foo) {
// FooResource fooResource = super.instantiateResource(foo);
// fooResource.setFoo(foo);
//
// return fooResource;
// }
//
// public FooResource toResource(Foo foo) {
// return this.createResourceWithId(foo.getId(), foo);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/Foo.java
// @ApiModel(value = "Foo entity", description = "Complete info of a entity foo")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Foo {
//
// @ApiModelProperty(value = "Sample Id Attribute", required = true)
// private Long id;
//
// @ApiModelProperty(value = "Sample Text Attribute", required = true)
// @NotNull
// private String sampleTextAttribute;
//
// @ApiModelProperty(value = "Sample Local Date Attribute", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate sampleLocalDateAttribute;
//
// public Foo copyFrom(Foo other) {
// this.sampleTextAttribute = other.sampleTextAttribute;
// this.sampleLocalDateAttribute = other.sampleLocalDateAttribute;
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
// Path: src/main/java/com/edwise/completespring/controllers/FooController.java
import com.edwise.completespring.assemblers.FooResource;
import com.edwise.completespring.assemblers.FooResourceAssembler;
import com.edwise.completespring.entities.Foo;
import com.edwise.completespring.exceptions.InvalidRequestException;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.net.URI;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
package com.edwise.completespring.controllers;
@RestController
@RequestMapping(value = "/api/foos/")
@Api(value = "foos", description = "Foo API", produces = "application/json")
@Slf4j
public class FooController {
private static final int RESPONSE_CODE_OK = 200;
private static final int RESPONSE_CODE_CREATED = 201;
private static final int RESPONSE_CODE_NO_RESPONSE = 204;
private static final String TEST_ATTRIBUTE_1 = "AttText1";
@Autowired
private FooResourceAssembler fooResourceAssembler;
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get Foos", notes = "Returns all foos")
@ApiResponses({
@ApiResponse(code = RESPONSE_CODE_OK, response = FooResource.class, message = "Exits one foo at least")
})
public ResponseEntity<List<FooResource>> getAll() { | List<Foo> foos = Arrays.asList( |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/controllers/FooController.java | // Path: src/main/java/com/edwise/completespring/assemblers/FooResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class FooResource extends ResourceSupport {
// private Foo foo;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/FooResourceAssembler.java
// @Component
// public class FooResourceAssembler extends ResourceAssemblerSupport<Foo, FooResource> {
//
// public FooResourceAssembler() {
// super(FooController.class, FooResource.class);
// }
//
// @Override
// protected FooResource instantiateResource(Foo foo) {
// FooResource fooResource = super.instantiateResource(foo);
// fooResource.setFoo(foo);
//
// return fooResource;
// }
//
// public FooResource toResource(Foo foo) {
// return this.createResourceWithId(foo.getId(), foo);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/Foo.java
// @ApiModel(value = "Foo entity", description = "Complete info of a entity foo")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Foo {
//
// @ApiModelProperty(value = "Sample Id Attribute", required = true)
// private Long id;
//
// @ApiModelProperty(value = "Sample Text Attribute", required = true)
// @NotNull
// private String sampleTextAttribute;
//
// @ApiModelProperty(value = "Sample Local Date Attribute", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate sampleLocalDateAttribute;
//
// public Foo copyFrom(Foo other) {
// this.sampleTextAttribute = other.sampleTextAttribute;
// this.sampleLocalDateAttribute = other.sampleLocalDateAttribute;
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
| import com.edwise.completespring.assemblers.FooResource;
import com.edwise.completespring.assemblers.FooResourceAssembler;
import com.edwise.completespring.entities.Foo;
import com.edwise.completespring.exceptions.InvalidRequestException;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.net.URI;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List; | List<FooResource> resourceList = fooResourceAssembler.toResources(foos);
log.info("Foos found: {}", foos);
return new ResponseEntity<>(resourceList, HttpStatus.OK);
}
@RequestMapping(method = RequestMethod.GET, value = "{id}", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get one Foo", response = FooResource.class, notes = "Returns one foo")
@ApiResponses({
@ApiResponse(code = RESPONSE_CODE_OK, message = "Exists this foo")
})
public ResponseEntity<FooResource> getFoo(@ApiParam(defaultValue = "1", value = "The id of the foo to return")
@PathVariable long id) {
FooResource resource = fooResourceAssembler.toResource(
new Foo().setId(id).setSampleTextAttribute(TEST_ATTRIBUTE_1).setSampleLocalDateAttribute(LocalDate.now())
);
log.info("Foo found: {}", resource.getFoo());
return new ResponseEntity<>(resource, HttpStatus.OK);
}
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Create Foo", notes = "Create a foo")
@ApiResponses({
@ApiResponse(code = RESPONSE_CODE_CREATED, message = "Successful create of a foo")
})
public ResponseEntity<FooResource> createFoo(@Valid @RequestBody Foo foo, BindingResult errors) {
if (errors.hasErrors()) { | // Path: src/main/java/com/edwise/completespring/assemblers/FooResource.java
// @Getter
// @Setter
// @Accessors(chain = true)
// public class FooResource extends ResourceSupport {
// private Foo foo;
// }
//
// Path: src/main/java/com/edwise/completespring/assemblers/FooResourceAssembler.java
// @Component
// public class FooResourceAssembler extends ResourceAssemblerSupport<Foo, FooResource> {
//
// public FooResourceAssembler() {
// super(FooController.class, FooResource.class);
// }
//
// @Override
// protected FooResource instantiateResource(Foo foo) {
// FooResource fooResource = super.instantiateResource(foo);
// fooResource.setFoo(foo);
//
// return fooResource;
// }
//
// public FooResource toResource(Foo foo) {
// return this.createResourceWithId(foo.getId(), foo);
// }
// }
//
// Path: src/main/java/com/edwise/completespring/entities/Foo.java
// @ApiModel(value = "Foo entity", description = "Complete info of a entity foo")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class Foo {
//
// @ApiModelProperty(value = "Sample Id Attribute", required = true)
// private Long id;
//
// @ApiModelProperty(value = "Sample Text Attribute", required = true)
// @NotNull
// private String sampleTextAttribute;
//
// @ApiModelProperty(value = "Sample Local Date Attribute", required = true, dataType = "LocalDate")
// @NotNull
// private LocalDate sampleLocalDateAttribute;
//
// public Foo copyFrom(Foo other) {
// this.sampleTextAttribute = other.sampleTextAttribute;
// this.sampleLocalDateAttribute = other.sampleLocalDateAttribute;
//
// return this;
// }
// }
//
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//
// @Getter
// private final ErrorInfo errors;
//
// public InvalidRequestException(BindingResult bindingResultErrors) {
// super(bindingResultErrors.toString());
// this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
// }
//
// }
// Path: src/main/java/com/edwise/completespring/controllers/FooController.java
import com.edwise.completespring.assemblers.FooResource;
import com.edwise.completespring.assemblers.FooResourceAssembler;
import com.edwise.completespring.entities.Foo;
import com.edwise.completespring.exceptions.InvalidRequestException;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.net.URI;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
List<FooResource> resourceList = fooResourceAssembler.toResources(foos);
log.info("Foos found: {}", foos);
return new ResponseEntity<>(resourceList, HttpStatus.OK);
}
@RequestMapping(method = RequestMethod.GET, value = "{id}", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get one Foo", response = FooResource.class, notes = "Returns one foo")
@ApiResponses({
@ApiResponse(code = RESPONSE_CODE_OK, message = "Exists this foo")
})
public ResponseEntity<FooResource> getFoo(@ApiParam(defaultValue = "1", value = "The id of the foo to return")
@PathVariable long id) {
FooResource resource = fooResourceAssembler.toResource(
new Foo().setId(id).setSampleTextAttribute(TEST_ATTRIBUTE_1).setSampleLocalDateAttribute(LocalDate.now())
);
log.info("Foo found: {}", resource.getFoo());
return new ResponseEntity<>(resource, HttpStatus.OK);
}
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Create Foo", notes = "Create a foo")
@ApiResponses({
@ApiResponse(code = RESPONSE_CODE_CREATED, message = "Successful create of a foo")
})
public ResponseEntity<FooResource> createFoo(@Valid @RequestBody Foo foo, BindingResult errors) {
if (errors.hasErrors()) { | throw new InvalidRequestException(errors); |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/config/SpringSecurityAuthenticationConfig.java | // Path: src/main/java/com/edwise/completespring/entities/UserAccount.java
// @Document(collection = "users")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class UserAccount {
//
// @Id
// private Long id;
//
// private String username;
// private String password;
//
// @NonNull
// private UserAccountType userType = UserAccountType.REST_USER;
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
| import com.edwise.completespring.entities.UserAccount;
import com.edwise.completespring.repositories.UserAccountRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configuration.GlobalAuthenticationConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException; | package com.edwise.completespring.config;
@Configuration
@Slf4j
public class SpringSecurityAuthenticationConfig extends GlobalAuthenticationConfigurerAdapter {
@Autowired | // Path: src/main/java/com/edwise/completespring/entities/UserAccount.java
// @Document(collection = "users")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class UserAccount {
//
// @Id
// private Long id;
//
// private String username;
// private String password;
//
// @NonNull
// private UserAccountType userType = UserAccountType.REST_USER;
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
// Path: src/main/java/com/edwise/completespring/config/SpringSecurityAuthenticationConfig.java
import com.edwise.completespring.entities.UserAccount;
import com.edwise.completespring.repositories.UserAccountRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configuration.GlobalAuthenticationConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
package com.edwise.completespring.config;
@Configuration
@Slf4j
public class SpringSecurityAuthenticationConfig extends GlobalAuthenticationConfigurerAdapter {
@Autowired | private UserAccountRepository userAccountRepository; |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/config/SpringSecurityAuthenticationConfig.java | // Path: src/main/java/com/edwise/completespring/entities/UserAccount.java
// @Document(collection = "users")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class UserAccount {
//
// @Id
// private Long id;
//
// private String username;
// private String password;
//
// @NonNull
// private UserAccountType userType = UserAccountType.REST_USER;
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
| import com.edwise.completespring.entities.UserAccount;
import com.edwise.completespring.repositories.UserAccountRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configuration.GlobalAuthenticationConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException; | package com.edwise.completespring.config;
@Configuration
@Slf4j
public class SpringSecurityAuthenticationConfig extends GlobalAuthenticationConfigurerAdapter {
@Autowired
private UserAccountRepository userAccountRepository;
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService());
}
@Bean
UserDetailsService userDetailsService() {
return username -> { | // Path: src/main/java/com/edwise/completespring/entities/UserAccount.java
// @Document(collection = "users")
// @Data
// @Accessors(chain = true)
// @EqualsAndHashCode(exclude = {"id"}, doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class UserAccount {
//
// @Id
// private Long id;
//
// private String username;
// private String password;
//
// @NonNull
// private UserAccountType userType = UserAccountType.REST_USER;
// }
//
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
//
// UserAccount findByUsername(String username);
// }
// Path: src/main/java/com/edwise/completespring/config/SpringSecurityAuthenticationConfig.java
import com.edwise.completespring.entities.UserAccount;
import com.edwise.completespring.repositories.UserAccountRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configuration.GlobalAuthenticationConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
package com.edwise.completespring.config;
@Configuration
@Slf4j
public class SpringSecurityAuthenticationConfig extends GlobalAuthenticationConfigurerAdapter {
@Autowired
private UserAccountRepository userAccountRepository;
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService());
}
@Bean
UserDetailsService userDetailsService() {
return username -> { | UserAccount userAccount = userAccountRepository.findByUsername(username); |
edwise/complete-spring-project | src/main/java/com/edwise/completespring/Application.java | // Path: src/main/java/com/edwise/completespring/dbutils/DataLoader.java
// @Slf4j
// @Component
// public class DataLoader {
// private static final String USERACCOUNTS_COLLECTION = "users";
// private static final Long BOOKS_INITIAL_SEQUENCE = 4L;
// private static final Long USERACCOUNTS_INITIAL_SEQUENCE = 3L;
// public static final Long BOOK_ID_1 = 1L;
// public static final Long BOOK_ID_2 = 2L;
// public static final Long BOOK_ID_3 = 3L;
// private static final Long BOOK_ID_4 = 4L;
// private static final Long USER_ID_1 = 1L;
// private static final Long USER_ID_2 = 2L;
// public static final String USER = "user1";
// public static final String PASSWORD_USER = "password1";
// public static final String ADMIN = "admin";
// public static final String PASSWORD_ADMIN = "password1234";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private UserAccountRepository userAccountRepository;
//
// @Autowired
// private SequenceIdRepository sequenceRepository;
//
// @Autowired
// private PasswordEncoder passwordEncoder;
//
// public void fillDBData() {
// log.info("Filling DB data...");
// fillDBUsersData();
// fillDBBooksData();
// log.info("DB filled with data.");
// }
//
// private void fillDBUsersData() {
// sequenceRepository.save(new SequenceId()
// .setId(USERACCOUNTS_COLLECTION)
// .setSeq(USERACCOUNTS_INITIAL_SEQUENCE)
// );
// userAccountRepository.deleteAll();
// Arrays.asList(
// new UserAccount()
// .setId(USER_ID_1)
// .setUsername(USER)
// .setPassword(passwordEncoder.encode(PASSWORD_USER))
// .setUserType(UserAccountType.REST_USER),
// new UserAccount()
// .setId(USER_ID_2)
// .setUsername(ADMIN)
// .setPassword(passwordEncoder.encode(PASSWORD_ADMIN))
// .setUserType(UserAccountType.ADMIN_USER))
// .forEach(userAccountRepository::save);
// }
//
// private void fillDBBooksData() {
// sequenceRepository.save(new SequenceId()
// .setId(BookServiceImpl.BOOK_COLLECTION)
// .setSeq(BOOKS_INITIAL_SEQUENCE)
// );
// bookRepository.deleteAll();
// Arrays.asList(
// new Book()
// .setId(BOOK_ID_1)
// .setTitle("Libro prueba mongo")
// .setAuthors(Collections.singletonList(new Author().setName("Edu").setSurname("Antón")))
// .setIsbn("11-333-12")
// .setReleaseDate(LocalDate.now())
// .setPublisher(new Publisher().setName("Editorial 1").setCountry("ES").setOnline(false)),
// new Book()
// .setId(BOOK_ID_2)
// .setTitle("Libro prueba mongo 2")
// .setAuthors(
// Arrays.asList(
// new Author().setName("Otro").setSurname("Más"),
// new Author().setName("S.").setSurname("King")))
// .setIsbn("12-1234-12")
// .setReleaseDate(LocalDate.now())
// .setPublisher(new Publisher().setName("Editorial 4").setCountry("UK").setOnline(true)),
// new Book()
// .setId(BOOK_ID_3)
// .setTitle("Libro prueba mongo 3")
// .setAuthors(Collections.singletonList(new Author().setName("Nadie").setSurname("Nobody")))
// .setIsbn("12-9999-92")
// .setReleaseDate(LocalDate.now())
// .setPublisher(new Publisher().setName("Editorial 7").setCountry("ES").setOnline(true)),
// new Book()
// .setId(BOOK_ID_4)
// .setTitle("Libro prueba mongo 4")
// .setAuthors(Collections.singletonList(new Author().setName("Perry").setSurname("Mason")))
// .setIsbn("22-34565-12")
// .setReleaseDate(LocalDate.now())
// .setPublisher(new Publisher().setName("Editorial 33").setCountry("US").setOnline(true)))
// .forEach(bookRepository::save);
// }
// }
| import com.edwise.completespring.dbutils.DataLoader;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean; | package com.edwise.completespring;
/**
* Spring Boot Application class
*/
@Slf4j
@SpringBootApplication
public class Application {
@Autowired | // Path: src/main/java/com/edwise/completespring/dbutils/DataLoader.java
// @Slf4j
// @Component
// public class DataLoader {
// private static final String USERACCOUNTS_COLLECTION = "users";
// private static final Long BOOKS_INITIAL_SEQUENCE = 4L;
// private static final Long USERACCOUNTS_INITIAL_SEQUENCE = 3L;
// public static final Long BOOK_ID_1 = 1L;
// public static final Long BOOK_ID_2 = 2L;
// public static final Long BOOK_ID_3 = 3L;
// private static final Long BOOK_ID_4 = 4L;
// private static final Long USER_ID_1 = 1L;
// private static final Long USER_ID_2 = 2L;
// public static final String USER = "user1";
// public static final String PASSWORD_USER = "password1";
// public static final String ADMIN = "admin";
// public static final String PASSWORD_ADMIN = "password1234";
//
// @Autowired
// private BookRepository bookRepository;
//
// @Autowired
// private UserAccountRepository userAccountRepository;
//
// @Autowired
// private SequenceIdRepository sequenceRepository;
//
// @Autowired
// private PasswordEncoder passwordEncoder;
//
// public void fillDBData() {
// log.info("Filling DB data...");
// fillDBUsersData();
// fillDBBooksData();
// log.info("DB filled with data.");
// }
//
// private void fillDBUsersData() {
// sequenceRepository.save(new SequenceId()
// .setId(USERACCOUNTS_COLLECTION)
// .setSeq(USERACCOUNTS_INITIAL_SEQUENCE)
// );
// userAccountRepository.deleteAll();
// Arrays.asList(
// new UserAccount()
// .setId(USER_ID_1)
// .setUsername(USER)
// .setPassword(passwordEncoder.encode(PASSWORD_USER))
// .setUserType(UserAccountType.REST_USER),
// new UserAccount()
// .setId(USER_ID_2)
// .setUsername(ADMIN)
// .setPassword(passwordEncoder.encode(PASSWORD_ADMIN))
// .setUserType(UserAccountType.ADMIN_USER))
// .forEach(userAccountRepository::save);
// }
//
// private void fillDBBooksData() {
// sequenceRepository.save(new SequenceId()
// .setId(BookServiceImpl.BOOK_COLLECTION)
// .setSeq(BOOKS_INITIAL_SEQUENCE)
// );
// bookRepository.deleteAll();
// Arrays.asList(
// new Book()
// .setId(BOOK_ID_1)
// .setTitle("Libro prueba mongo")
// .setAuthors(Collections.singletonList(new Author().setName("Edu").setSurname("Antón")))
// .setIsbn("11-333-12")
// .setReleaseDate(LocalDate.now())
// .setPublisher(new Publisher().setName("Editorial 1").setCountry("ES").setOnline(false)),
// new Book()
// .setId(BOOK_ID_2)
// .setTitle("Libro prueba mongo 2")
// .setAuthors(
// Arrays.asList(
// new Author().setName("Otro").setSurname("Más"),
// new Author().setName("S.").setSurname("King")))
// .setIsbn("12-1234-12")
// .setReleaseDate(LocalDate.now())
// .setPublisher(new Publisher().setName("Editorial 4").setCountry("UK").setOnline(true)),
// new Book()
// .setId(BOOK_ID_3)
// .setTitle("Libro prueba mongo 3")
// .setAuthors(Collections.singletonList(new Author().setName("Nadie").setSurname("Nobody")))
// .setIsbn("12-9999-92")
// .setReleaseDate(LocalDate.now())
// .setPublisher(new Publisher().setName("Editorial 7").setCountry("ES").setOnline(true)),
// new Book()
// .setId(BOOK_ID_4)
// .setTitle("Libro prueba mongo 4")
// .setAuthors(Collections.singletonList(new Author().setName("Perry").setSurname("Mason")))
// .setIsbn("22-34565-12")
// .setReleaseDate(LocalDate.now())
// .setPublisher(new Publisher().setName("Editorial 33").setCountry("US").setOnline(true)))
// .forEach(bookRepository::save);
// }
// }
// Path: src/main/java/com/edwise/completespring/Application.java
import com.edwise.completespring.dbutils.DataLoader;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
package com.edwise.completespring;
/**
* Spring Boot Application class
*/
@Slf4j
@SpringBootApplication
public class Application {
@Autowired | private DataLoader dataLoader; |
tmalaska/hadcom.utils | src/main/java/com/cloudera/sa/hcu/io/put/hdfs/writer/RcFileWriter.java | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
| import java.io.IOException;
import java.util.Properties;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.ql.io.RCFile;
import org.apache.hadoop.hive.serde2.columnar.BytesRefArrayWritable;
import org.apache.hadoop.hive.serde2.columnar.BytesRefWritable;
import com.cloudera.sa.hcu.utils.PropertyUtils; | package com.cloudera.sa.hcu.io.put.hdfs.writer;
public class RcFileWriter extends AbstractWriter
{
RCFile.Writer writer;
int maxColumns;
public static final String CONF_MAX_COLUMNS = "writer.max.columns";
public static final String CONF_COMPRESSION_CODEC = COMPRESSION_CODEC;
public RcFileWriter(Properties p) throws Exception
{
super(p);
}
public RcFileWriter(String outputPath, int maxColumns, String compressionCodec) throws IOException
{
super(makeProperties(outputPath, maxColumns, compressionCodec));
}
private static Properties makeProperties(String outputPath, int maxColumns, String compressionCodec)
{
Properties p = new Properties();
p.setProperty(CONF_OUTPUT_PATH, outputPath);
p.setProperty(CONF_MAX_COLUMNS, Integer.toString(maxColumns));
p.setProperty(CONF_COMPRESSION_CODEC, compressionCodec);
return p;
}
@Override
protected void init(String outputPath, Properties p) throws IOException
{ | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
// Path: src/main/java/com/cloudera/sa/hcu/io/put/hdfs/writer/RcFileWriter.java
import java.io.IOException;
import java.util.Properties;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.ql.io.RCFile;
import org.apache.hadoop.hive.serde2.columnar.BytesRefArrayWritable;
import org.apache.hadoop.hive.serde2.columnar.BytesRefWritable;
import com.cloudera.sa.hcu.utils.PropertyUtils;
package com.cloudera.sa.hcu.io.put.hdfs.writer;
public class RcFileWriter extends AbstractWriter
{
RCFile.Writer writer;
int maxColumns;
public static final String CONF_MAX_COLUMNS = "writer.max.columns";
public static final String CONF_COMPRESSION_CODEC = COMPRESSION_CODEC;
public RcFileWriter(Properties p) throws Exception
{
super(p);
}
public RcFileWriter(String outputPath, int maxColumns, String compressionCodec) throws IOException
{
super(makeProperties(outputPath, maxColumns, compressionCodec));
}
private static Properties makeProperties(String outputPath, int maxColumns, String compressionCodec)
{
Properties p = new Properties();
p.setProperty(CONF_OUTPUT_PATH, outputPath);
p.setProperty(CONF_MAX_COLUMNS, Integer.toString(maxColumns));
p.setProperty(CONF_COMPRESSION_CODEC, compressionCodec);
return p;
}
@Override
protected void init(String outputPath, Properties p) throws IOException
{ | this.maxColumns = PropertyUtils.getIntProperty(p, CONF_MAX_COLUMNS); |
tmalaska/hadcom.utils | src/main/java/com/cloudera/sa/hcu/io/console/out/ConsoleOutMain.java | // Path: src/main/java/com/cloudera/sa/hcu/io/out/ConsoleOutAvroFile.java
// public class ConsoleOutAvroFile {
//
// /**
// * @param args
// * @throws IOException
// */
// public static void main(String[] args) throws IOException
// {
// if (args.length < 1)
// {
// System.out.println("ConsoleOutAvroFile:");
// System.out.println("");
// System.out.println("Parameter: <inputFile>");
// return;
// }
//
// String inputFile = args[0];
//
//
// Configuration config = new Configuration();
// FileSystem hdfs = FileSystem.get(config);
//
// Path inputFilePath = new Path(inputFile);
//
// FSDataInputStream dataInputStream = hdfs.open(inputFilePath);
//
// DatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>();
// //writer.setSchema(s); // I guess I don't need this
//
// DataFileStream<GenericRecord> dataFileReader = new DataFileStream<GenericRecord>(dataInputStream, reader);
//
// Schema s = dataFileReader.getSchema();
// System.out.println(s.getName() + " " + s);
//
// System.out.println("-");
//
// while(dataFileReader.hasNext())
// {
// GenericRecord record = dataFileReader.next();
// record.toString();
//
// System.out.println(" " + record);
// }
//
// System.out.println("-");
//
// dataFileReader.close();
// dataInputStream.close();
// }
//
// }
//
// Path: src/main/java/com/cloudera/sa/hcu/io/out/ConsoleOutRcFile.java
// public class ConsoleOutRcFile {
//
// /**
// * @param args
// * @throws IOException
// */
// public static void main(String[] args) throws IOException
// {
// if (args.length < 1)
// {
// System.out.println("ConsoleOutRcFile:");
// System.out.println("Parameter: <inputFile> <optional delimiter>");
// }
// String inputFile = args[0];
//
//
// String delimiter = "|";
// if (args.length > 1)
// {
// delimiter = args[1];
// }
//
// Configuration config = new Configuration();
// FileSystem hdfs = FileSystem.get(config);
//
// Path inputFilePath = new Path(inputFile);
//
//
// RCFile.Reader reader = new RCFile.Reader(hdfs, inputFilePath, config);
//
// LongWritable next = new LongWritable(1);
//
// BytesRefArrayWritable row = new BytesRefArrayWritable();
//
//
// while(reader.next(next))
// {
// reader.getCurrentRow(row);
//
// for (int j = 0; j < row.size(); j++)
// {
// BytesRefWritable byteWritable = row.get(j);
// if (byteWritable.getStart() >= 0 && byteWritable.getLength() > 0)
// {
// System.out.print(new String(byteWritable.getData()).substring(byteWritable.getStart(), byteWritable.getStart() + byteWritable.getLength()));
//
// }
// if (j < row.size()-1)
// {
// System.out.print(delimiter);
// }
// }
//
// System.out.println("");
// }
//
//
// reader.close();
// }
//
// }
| import com.cloudera.sa.hcu.io.out.ConsoleOutAvroFile;
import com.cloudera.sa.hcu.io.out.ConsoleOutRcFile; | package com.cloudera.sa.hcu.io.console.out;
public class ConsoleOutMain
{
public static void main(String[] args) throws Exception
{
if (args.length < 1)
{
outputConsoleHelp();
return;
}
String[] subCommand = args;
String[] subCommandArgs = new String[subCommand.length-1];
System.arraycopy( subCommand, 1, subCommandArgs, 0, subCommandArgs.length );
if (subCommand[0].equals("avro"))
{ | // Path: src/main/java/com/cloudera/sa/hcu/io/out/ConsoleOutAvroFile.java
// public class ConsoleOutAvroFile {
//
// /**
// * @param args
// * @throws IOException
// */
// public static void main(String[] args) throws IOException
// {
// if (args.length < 1)
// {
// System.out.println("ConsoleOutAvroFile:");
// System.out.println("");
// System.out.println("Parameter: <inputFile>");
// return;
// }
//
// String inputFile = args[0];
//
//
// Configuration config = new Configuration();
// FileSystem hdfs = FileSystem.get(config);
//
// Path inputFilePath = new Path(inputFile);
//
// FSDataInputStream dataInputStream = hdfs.open(inputFilePath);
//
// DatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>();
// //writer.setSchema(s); // I guess I don't need this
//
// DataFileStream<GenericRecord> dataFileReader = new DataFileStream<GenericRecord>(dataInputStream, reader);
//
// Schema s = dataFileReader.getSchema();
// System.out.println(s.getName() + " " + s);
//
// System.out.println("-");
//
// while(dataFileReader.hasNext())
// {
// GenericRecord record = dataFileReader.next();
// record.toString();
//
// System.out.println(" " + record);
// }
//
// System.out.println("-");
//
// dataFileReader.close();
// dataInputStream.close();
// }
//
// }
//
// Path: src/main/java/com/cloudera/sa/hcu/io/out/ConsoleOutRcFile.java
// public class ConsoleOutRcFile {
//
// /**
// * @param args
// * @throws IOException
// */
// public static void main(String[] args) throws IOException
// {
// if (args.length < 1)
// {
// System.out.println("ConsoleOutRcFile:");
// System.out.println("Parameter: <inputFile> <optional delimiter>");
// }
// String inputFile = args[0];
//
//
// String delimiter = "|";
// if (args.length > 1)
// {
// delimiter = args[1];
// }
//
// Configuration config = new Configuration();
// FileSystem hdfs = FileSystem.get(config);
//
// Path inputFilePath = new Path(inputFile);
//
//
// RCFile.Reader reader = new RCFile.Reader(hdfs, inputFilePath, config);
//
// LongWritable next = new LongWritable(1);
//
// BytesRefArrayWritable row = new BytesRefArrayWritable();
//
//
// while(reader.next(next))
// {
// reader.getCurrentRow(row);
//
// for (int j = 0; j < row.size(); j++)
// {
// BytesRefWritable byteWritable = row.get(j);
// if (byteWritable.getStart() >= 0 && byteWritable.getLength() > 0)
// {
// System.out.print(new String(byteWritable.getData()).substring(byteWritable.getStart(), byteWritable.getStart() + byteWritable.getLength()));
//
// }
// if (j < row.size()-1)
// {
// System.out.print(delimiter);
// }
// }
//
// System.out.println("");
// }
//
//
// reader.close();
// }
//
// }
// Path: src/main/java/com/cloudera/sa/hcu/io/console/out/ConsoleOutMain.java
import com.cloudera.sa.hcu.io.out.ConsoleOutAvroFile;
import com.cloudera.sa.hcu.io.out.ConsoleOutRcFile;
package com.cloudera.sa.hcu.io.console.out;
public class ConsoleOutMain
{
public static void main(String[] args) throws Exception
{
if (args.length < 1)
{
outputConsoleHelp();
return;
}
String[] subCommand = args;
String[] subCommandArgs = new String[subCommand.length-1];
System.arraycopy( subCommand, 1, subCommandArgs, 0, subCommandArgs.length );
if (subCommand[0].equals("avro"))
{ | ConsoleOutAvroFile.main(subCommandArgs); |
tmalaska/hadcom.utils | src/main/java/com/cloudera/sa/hcu/io/console/out/ConsoleOutMain.java | // Path: src/main/java/com/cloudera/sa/hcu/io/out/ConsoleOutAvroFile.java
// public class ConsoleOutAvroFile {
//
// /**
// * @param args
// * @throws IOException
// */
// public static void main(String[] args) throws IOException
// {
// if (args.length < 1)
// {
// System.out.println("ConsoleOutAvroFile:");
// System.out.println("");
// System.out.println("Parameter: <inputFile>");
// return;
// }
//
// String inputFile = args[0];
//
//
// Configuration config = new Configuration();
// FileSystem hdfs = FileSystem.get(config);
//
// Path inputFilePath = new Path(inputFile);
//
// FSDataInputStream dataInputStream = hdfs.open(inputFilePath);
//
// DatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>();
// //writer.setSchema(s); // I guess I don't need this
//
// DataFileStream<GenericRecord> dataFileReader = new DataFileStream<GenericRecord>(dataInputStream, reader);
//
// Schema s = dataFileReader.getSchema();
// System.out.println(s.getName() + " " + s);
//
// System.out.println("-");
//
// while(dataFileReader.hasNext())
// {
// GenericRecord record = dataFileReader.next();
// record.toString();
//
// System.out.println(" " + record);
// }
//
// System.out.println("-");
//
// dataFileReader.close();
// dataInputStream.close();
// }
//
// }
//
// Path: src/main/java/com/cloudera/sa/hcu/io/out/ConsoleOutRcFile.java
// public class ConsoleOutRcFile {
//
// /**
// * @param args
// * @throws IOException
// */
// public static void main(String[] args) throws IOException
// {
// if (args.length < 1)
// {
// System.out.println("ConsoleOutRcFile:");
// System.out.println("Parameter: <inputFile> <optional delimiter>");
// }
// String inputFile = args[0];
//
//
// String delimiter = "|";
// if (args.length > 1)
// {
// delimiter = args[1];
// }
//
// Configuration config = new Configuration();
// FileSystem hdfs = FileSystem.get(config);
//
// Path inputFilePath = new Path(inputFile);
//
//
// RCFile.Reader reader = new RCFile.Reader(hdfs, inputFilePath, config);
//
// LongWritable next = new LongWritable(1);
//
// BytesRefArrayWritable row = new BytesRefArrayWritable();
//
//
// while(reader.next(next))
// {
// reader.getCurrentRow(row);
//
// for (int j = 0; j < row.size(); j++)
// {
// BytesRefWritable byteWritable = row.get(j);
// if (byteWritable.getStart() >= 0 && byteWritable.getLength() > 0)
// {
// System.out.print(new String(byteWritable.getData()).substring(byteWritable.getStart(), byteWritable.getStart() + byteWritable.getLength()));
//
// }
// if (j < row.size()-1)
// {
// System.out.print(delimiter);
// }
// }
//
// System.out.println("");
// }
//
//
// reader.close();
// }
//
// }
| import com.cloudera.sa.hcu.io.out.ConsoleOutAvroFile;
import com.cloudera.sa.hcu.io.out.ConsoleOutRcFile; | package com.cloudera.sa.hcu.io.console.out;
public class ConsoleOutMain
{
public static void main(String[] args) throws Exception
{
if (args.length < 1)
{
outputConsoleHelp();
return;
}
String[] subCommand = args;
String[] subCommandArgs = new String[subCommand.length-1];
System.arraycopy( subCommand, 1, subCommandArgs, 0, subCommandArgs.length );
if (subCommand[0].equals("avro"))
{
ConsoleOutAvroFile.main(subCommandArgs);
}else if (subCommand[0].equals("rc"))
{ | // Path: src/main/java/com/cloudera/sa/hcu/io/out/ConsoleOutAvroFile.java
// public class ConsoleOutAvroFile {
//
// /**
// * @param args
// * @throws IOException
// */
// public static void main(String[] args) throws IOException
// {
// if (args.length < 1)
// {
// System.out.println("ConsoleOutAvroFile:");
// System.out.println("");
// System.out.println("Parameter: <inputFile>");
// return;
// }
//
// String inputFile = args[0];
//
//
// Configuration config = new Configuration();
// FileSystem hdfs = FileSystem.get(config);
//
// Path inputFilePath = new Path(inputFile);
//
// FSDataInputStream dataInputStream = hdfs.open(inputFilePath);
//
// DatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>();
// //writer.setSchema(s); // I guess I don't need this
//
// DataFileStream<GenericRecord> dataFileReader = new DataFileStream<GenericRecord>(dataInputStream, reader);
//
// Schema s = dataFileReader.getSchema();
// System.out.println(s.getName() + " " + s);
//
// System.out.println("-");
//
// while(dataFileReader.hasNext())
// {
// GenericRecord record = dataFileReader.next();
// record.toString();
//
// System.out.println(" " + record);
// }
//
// System.out.println("-");
//
// dataFileReader.close();
// dataInputStream.close();
// }
//
// }
//
// Path: src/main/java/com/cloudera/sa/hcu/io/out/ConsoleOutRcFile.java
// public class ConsoleOutRcFile {
//
// /**
// * @param args
// * @throws IOException
// */
// public static void main(String[] args) throws IOException
// {
// if (args.length < 1)
// {
// System.out.println("ConsoleOutRcFile:");
// System.out.println("Parameter: <inputFile> <optional delimiter>");
// }
// String inputFile = args[0];
//
//
// String delimiter = "|";
// if (args.length > 1)
// {
// delimiter = args[1];
// }
//
// Configuration config = new Configuration();
// FileSystem hdfs = FileSystem.get(config);
//
// Path inputFilePath = new Path(inputFile);
//
//
// RCFile.Reader reader = new RCFile.Reader(hdfs, inputFilePath, config);
//
// LongWritable next = new LongWritable(1);
//
// BytesRefArrayWritable row = new BytesRefArrayWritable();
//
//
// while(reader.next(next))
// {
// reader.getCurrentRow(row);
//
// for (int j = 0; j < row.size(); j++)
// {
// BytesRefWritable byteWritable = row.get(j);
// if (byteWritable.getStart() >= 0 && byteWritable.getLength() > 0)
// {
// System.out.print(new String(byteWritable.getData()).substring(byteWritable.getStart(), byteWritable.getStart() + byteWritable.getLength()));
//
// }
// if (j < row.size()-1)
// {
// System.out.print(delimiter);
// }
// }
//
// System.out.println("");
// }
//
//
// reader.close();
// }
//
// }
// Path: src/main/java/com/cloudera/sa/hcu/io/console/out/ConsoleOutMain.java
import com.cloudera.sa.hcu.io.out.ConsoleOutAvroFile;
import com.cloudera.sa.hcu.io.out.ConsoleOutRcFile;
package com.cloudera.sa.hcu.io.console.out;
public class ConsoleOutMain
{
public static void main(String[] args) throws Exception
{
if (args.length < 1)
{
outputConsoleHelp();
return;
}
String[] subCommand = args;
String[] subCommandArgs = new String[subCommand.length-1];
System.arraycopy( subCommand, 1, subCommandArgs, 0, subCommandArgs.length );
if (subCommand[0].equals("avro"))
{
ConsoleOutAvroFile.main(subCommandArgs);
}else if (subCommand[0].equals("rc"))
{ | ConsoleOutRcFile.main(subCommandArgs); |
tmalaska/hadcom.utils | src/main/java/com/cloudera/sa/hcu/io/put/local/reader/FlatFileReader.java | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
| import java.io.BufferedReader;
import java.io.IOException;
import java.util.Properties;
import com.cloudera.sa.hcu.utils.PropertyUtils; | package com.cloudera.sa.hcu.io.put.local.reader;
public class FlatFileReader extends LocalOneOrMoreFileColumnReader
{
private static final String CONF_FIELD_LENGTH_ARRAY = FIELD_LENGTH_ARRAY;
BufferedReader reader;
int[] lengthArray;
int totalLength;
public FlatFileReader(Properties p) throws Exception
{
super(p);
}
@Override
protected void init(String[] inputPaths, Properties p) throws IOException
{ | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
// Path: src/main/java/com/cloudera/sa/hcu/io/put/local/reader/FlatFileReader.java
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Properties;
import com.cloudera.sa.hcu.utils.PropertyUtils;
package com.cloudera.sa.hcu.io.put.local.reader;
public class FlatFileReader extends LocalOneOrMoreFileColumnReader
{
private static final String CONF_FIELD_LENGTH_ARRAY = FIELD_LENGTH_ARRAY;
BufferedReader reader;
int[] lengthArray;
int totalLength;
public FlatFileReader(Properties p) throws Exception
{
super(p);
}
@Override
protected void init(String[] inputPaths, Properties p) throws IOException
{ | lengthArray = PropertyUtils.getIntArrayProperty(p, CONF_FIELD_LENGTH_ARRAY); |
tmalaska/hadcom.utils | src/main/java/com/cloudera/sa/hcu/io/put/local/reader/CsvReader.java | // Path: src/main/java/com/cloudera/sa/hcu/io/utils/LocalFileUtils.java
// public class LocalFileUtils
// {
//
//
// public static File[] createFileArray(String[] filePathArray)
// {
// ArrayList<File> fileList = new ArrayList<File>();
// File[] tempFileArray;
//
// for (String filePath: filePathArray)
// {
// File origFile = new File(filePath);
//
// if (origFile.isDirectory())
// {
// tempFileArray = origFile.listFiles();
//
// for (File file: tempFileArray)
// {
// fileList.add(file);
// }
// }else
// {
// fileList.add(origFile);
// }
// }
//
// return fileList.toArray(new File[0]);
// }
//
// public static String[] createStringArrayOfFiles(String[] filePathArray)
// {
// ArrayList<String> filePathList = new ArrayList<String>();
// File[] tempFileArray;
//
// for (String filePath: filePathArray)
// {
// File origFile = new File(filePath);
//
// if (origFile.isDirectory())
// {
// tempFileArray = origFile.listFiles();
//
// for (File file: tempFileArray)
// {
// filePathList.add(file.getAbsolutePath());
// }
// }else
// {
// filePathList.add(origFile.getAbsolutePath());
// }
// }
//
// return filePathList.toArray(new String[0]);
// }
//
//
// }
| import java.io.IOException;
import java.util.Properties;
import com.cloudera.sa.hcu.io.utils.LocalFileUtils;
import au.com.bytecode.opencsv.CSVReader; | package com.cloudera.sa.hcu.io.put.local.reader;
public class CsvReader extends LocalOneOrMoreFileColumnReader
{
CSVReader csvReader;
public CsvReader(Properties prop) throws Exception
{
super(prop);
}
protected void loadFile(String[] filePathArray) throws IOException
{ | // Path: src/main/java/com/cloudera/sa/hcu/io/utils/LocalFileUtils.java
// public class LocalFileUtils
// {
//
//
// public static File[] createFileArray(String[] filePathArray)
// {
// ArrayList<File> fileList = new ArrayList<File>();
// File[] tempFileArray;
//
// for (String filePath: filePathArray)
// {
// File origFile = new File(filePath);
//
// if (origFile.isDirectory())
// {
// tempFileArray = origFile.listFiles();
//
// for (File file: tempFileArray)
// {
// fileList.add(file);
// }
// }else
// {
// fileList.add(origFile);
// }
// }
//
// return fileList.toArray(new File[0]);
// }
//
// public static String[] createStringArrayOfFiles(String[] filePathArray)
// {
// ArrayList<String> filePathList = new ArrayList<String>();
// File[] tempFileArray;
//
// for (String filePath: filePathArray)
// {
// File origFile = new File(filePath);
//
// if (origFile.isDirectory())
// {
// tempFileArray = origFile.listFiles();
//
// for (File file: tempFileArray)
// {
// filePathList.add(file.getAbsolutePath());
// }
// }else
// {
// filePathList.add(origFile.getAbsolutePath());
// }
// }
//
// return filePathList.toArray(new String[0]);
// }
//
//
// }
// Path: src/main/java/com/cloudera/sa/hcu/io/put/local/reader/CsvReader.java
import java.io.IOException;
import java.util.Properties;
import com.cloudera.sa.hcu.io.utils.LocalFileUtils;
import au.com.bytecode.opencsv.CSVReader;
package com.cloudera.sa.hcu.io.put.local.reader;
public class CsvReader extends LocalOneOrMoreFileColumnReader
{
CSVReader csvReader;
public CsvReader(Properties prop) throws Exception
{
super(prop);
}
protected void loadFile(String[] filePathArray) throws IOException
{ | fileArray = LocalFileUtils.createFileArray(filePathArray); |
tmalaska/hadcom.utils | src/main/java/com/cloudera/sa/hcu/io/put/hdfs/writer/SequenceFileDelimiterWriter.java | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
| import java.io.IOException;
import java.util.EnumSet;
import java.util.Properties;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CreateFlag;
import org.apache.hadoop.fs.FileContext;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text;
import com.cloudera.sa.hcu.utils.PropertyUtils; | package com.cloudera.sa.hcu.io.put.hdfs.writer;
public class SequenceFileDelimiterWriter extends AbstractWriter
{
private static final String CONF_DELIMITER = "writer.delimiter";
private static final String CONF_COMPRESSION_CODEC = COMPRESSION_CODEC;
SequenceFile.Writer writer;
String regexDelimiter;
Text value = new Text();
public SequenceFileDelimiterWriter(Properties p) throws Exception
{
super(p);
}
public SequenceFileDelimiterWriter(String outputPath, String regexDelimiter, String compressionCodec) throws IOException
{
super( makeProperties(outputPath, regexDelimiter, compressionCodec));
}
private static Properties makeProperties(String outputPath, String regexDelimiter, String compressionCodec)
{
Properties p = new Properties();
p.setProperty(CONF_OUTPUT_PATH, outputPath);
p.setProperty(CONF_DELIMITER, regexDelimiter);
p.setProperty(CONF_COMPRESSION_CODEC, compressionCodec);
return p;
}
@Override
protected void init(String outputPath, Properties p) throws IOException
{ | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
// Path: src/main/java/com/cloudera/sa/hcu/io/put/hdfs/writer/SequenceFileDelimiterWriter.java
import java.io.IOException;
import java.util.EnumSet;
import java.util.Properties;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CreateFlag;
import org.apache.hadoop.fs.FileContext;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text;
import com.cloudera.sa.hcu.utils.PropertyUtils;
package com.cloudera.sa.hcu.io.put.hdfs.writer;
public class SequenceFileDelimiterWriter extends AbstractWriter
{
private static final String CONF_DELIMITER = "writer.delimiter";
private static final String CONF_COMPRESSION_CODEC = COMPRESSION_CODEC;
SequenceFile.Writer writer;
String regexDelimiter;
Text value = new Text();
public SequenceFileDelimiterWriter(Properties p) throws Exception
{
super(p);
}
public SequenceFileDelimiterWriter(String outputPath, String regexDelimiter, String compressionCodec) throws IOException
{
super( makeProperties(outputPath, regexDelimiter, compressionCodec));
}
private static Properties makeProperties(String outputPath, String regexDelimiter, String compressionCodec)
{
Properties p = new Properties();
p.setProperty(CONF_OUTPUT_PATH, outputPath);
p.setProperty(CONF_DELIMITER, regexDelimiter);
p.setProperty(CONF_COMPRESSION_CODEC, compressionCodec);
return p;
}
@Override
protected void init(String outputPath, Properties p) throws IOException
{ | this.regexDelimiter = PropertyUtils.getStringProperty(p, CONF_DELIMITER); |
tmalaska/hadcom.utils | src/main/java/com/cloudera/sa/hcu/io/put/local/reader/FileNameAggregateFileReader.java | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
| import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Properties;
import com.cloudera.sa.hcu.utils.PropertyUtils; | package com.cloudera.sa.hcu.io.put.local.reader;
public class FileNameAggregateFileReader extends AbstractLocalFileColumnReader
{
public static final String CONF_READER = "reader.aggregate.reader";
AbstractLocalFileColumnReader rootReader;
public FileNameAggregateFileReader( Properties p) throws Exception
{
super(p);
}
@Override
protected void init(String[] inputPaths, Properties p) throws IOException, SecurityException, NoSuchMethodException, ClassNotFoundException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
{ | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
// Path: src/main/java/com/cloudera/sa/hcu/io/put/local/reader/FileNameAggregateFileReader.java
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Properties;
import com.cloudera.sa.hcu.utils.PropertyUtils;
package com.cloudera.sa.hcu.io.put.local.reader;
public class FileNameAggregateFileReader extends AbstractLocalFileColumnReader
{
public static final String CONF_READER = "reader.aggregate.reader";
AbstractLocalFileColumnReader rootReader;
public FileNameAggregateFileReader( Properties p) throws Exception
{
super(p);
}
@Override
protected void init(String[] inputPaths, Properties p) throws IOException, SecurityException, NoSuchMethodException, ClassNotFoundException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
{ | String className = PropertyUtils.getStringProperty(p, CONF_READER); |
tmalaska/hadcom.utils | src/main/java/com/cloudera/sa/hcu/io/route/RouteMain.java | // Path: src/main/java/com/cloudera/sa/hcu/io/route/scheduler/IRouteWorker.java
// public interface IRouteWorker
// {
//
// abstract public void start() throws Exception;
//
// abstract public void hardStop() throws Exception;
//
// abstract public void softStop() throws Exception;
// }
| import java.io.File;
import java.io.FileInputStream;
import java.lang.reflect.Constructor;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.regex.Pattern;
import com.cloudera.sa.hcu.io.route.scheduler.IRouteWorker; | package com.cloudera.sa.hcu.io.route;
public class RouteMain
{
public static final String CONF_ROOT_ROUTES = "route.";
public static void main(String[] args) throws Exception
{
if (args.length < 1)
{
System.out.println("Route Help:");
System.out.println("Parameters: <propertyFilePath>");
System.out.println();
return;
}
Properties p = new Properties();
p.load(new FileInputStream(new File(args[0])));
Pattern pattern = Pattern.compile("\\.");
for (Entry<Object, Object> entry: p.entrySet())
{
String[] keySplit = pattern.split(entry.getKey().toString());
if (keySplit.length == 2)
{
if (keySplit[0].equals("route"))
{
String routePrefix = keySplit[0] + "." + keySplit[1];
String routeClass = entry.getValue().toString();
try
{
Constructor constructor = Class.forName(routeClass).getConstructor(String.class, Properties.class);
| // Path: src/main/java/com/cloudera/sa/hcu/io/route/scheduler/IRouteWorker.java
// public interface IRouteWorker
// {
//
// abstract public void start() throws Exception;
//
// abstract public void hardStop() throws Exception;
//
// abstract public void softStop() throws Exception;
// }
// Path: src/main/java/com/cloudera/sa/hcu/io/route/RouteMain.java
import java.io.File;
import java.io.FileInputStream;
import java.lang.reflect.Constructor;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.regex.Pattern;
import com.cloudera.sa.hcu.io.route.scheduler.IRouteWorker;
package com.cloudera.sa.hcu.io.route;
public class RouteMain
{
public static final String CONF_ROOT_ROUTES = "route.";
public static void main(String[] args) throws Exception
{
if (args.length < 1)
{
System.out.println("Route Help:");
System.out.println("Parameters: <propertyFilePath>");
System.out.println();
return;
}
Properties p = new Properties();
p.load(new FileInputStream(new File(args[0])));
Pattern pattern = Pattern.compile("\\.");
for (Entry<Object, Object> entry: p.entrySet())
{
String[] keySplit = pattern.split(entry.getKey().toString());
if (keySplit.length == 2)
{
if (keySplit[0].equals("route"))
{
String routePrefix = keySplit[0] + "." + keySplit[1];
String routeClass = entry.getValue().toString();
try
{
Constructor constructor = Class.forName(routeClass).getConstructor(String.class, Properties.class);
| IRouteWorker route = (IRouteWorker)constructor.newInstance(routePrefix, p); |
tmalaska/hadcom.utils | src/main/java/com/cloudera/sa/hcu/io/put/local/reader/VaribleLengthDelimiterReader.java | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
| import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Pattern;
import com.cloudera.sa.hcu.utils.PropertyUtils; | package com.cloudera.sa.hcu.io.put.local.reader;
public class VaribleLengthDelimiterReader extends LocalOneOrMoreFileColumnReader
{
private static final String CONF_ROW_TYPE_INDEX = "reader.row.type.index";
private static final String CONF_DELIMITER_REGEX = DELIMITER_REGEX;
int rowTypeIndex = 0;
String currentRowType;
Pattern pattern;
BufferedReader reader;
public VaribleLengthDelimiterReader( Properties p) throws Exception
{
super(p);
}
@Override
protected void init(String[] inputPaths, Properties p) throws IOException
{ | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
// Path: src/main/java/com/cloudera/sa/hcu/io/put/local/reader/VaribleLengthDelimiterReader.java
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Pattern;
import com.cloudera.sa.hcu.utils.PropertyUtils;
package com.cloudera.sa.hcu.io.put.local.reader;
public class VaribleLengthDelimiterReader extends LocalOneOrMoreFileColumnReader
{
private static final String CONF_ROW_TYPE_INDEX = "reader.row.type.index";
private static final String CONF_DELIMITER_REGEX = DELIMITER_REGEX;
int rowTypeIndex = 0;
String currentRowType;
Pattern pattern;
BufferedReader reader;
public VaribleLengthDelimiterReader( Properties p) throws Exception
{
super(p);
}
@Override
protected void init(String[] inputPaths, Properties p) throws IOException
{ | rowTypeIndex = PropertyUtils.getIntProperty(p, CONF_ROW_TYPE_INDEX); |
tmalaska/hadcom.utils | src/main/java/com/cloudera/sa/hcu/io/put/local/reader/AbstractLocalFileColumnReader.java | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
| import java.io.IOException;
import java.util.Properties;
import com.cloudera.sa.hcu.utils.PropertyUtils; | package com.cloudera.sa.hcu.io.put.local.reader;
public abstract class AbstractLocalFileColumnReader
{
protected static final String DELIMITER_REGEX = "reader.delimiter.regex";
protected static final String FIELD_LENGTH_ARRAY = "reader.field.lengths";
public static final String CONF_INPUT_PATHS = "reader.inputPaths";
String[] inputPaths;
public AbstractLocalFileColumnReader(Properties prop) throws Exception
{ | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
// Path: src/main/java/com/cloudera/sa/hcu/io/put/local/reader/AbstractLocalFileColumnReader.java
import java.io.IOException;
import java.util.Properties;
import com.cloudera.sa.hcu.utils.PropertyUtils;
package com.cloudera.sa.hcu.io.put.local.reader;
public abstract class AbstractLocalFileColumnReader
{
protected static final String DELIMITER_REGEX = "reader.delimiter.regex";
protected static final String FIELD_LENGTH_ARRAY = "reader.field.lengths";
public static final String CONF_INPUT_PATHS = "reader.inputPaths";
String[] inputPaths;
public AbstractLocalFileColumnReader(Properties prop) throws Exception
{ | inputPaths = PropertyUtils.getStringProperty(prop, CONF_INPUT_PATHS).split(","); |
tmalaska/hadcom.utils | src/main/java/com/cloudera/sa/hcu/io/put/hdfs/writer/AbstractWriter.java | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
| import java.io.IOException;
import java.util.Properties;
import com.cloudera.sa.hcu.utils.PropertyUtils; | package com.cloudera.sa.hcu.io.put.hdfs.writer;
public abstract class AbstractWriter
{
protected static final String COMPRESSION_CODEC = "writer.compression.codec";
public static final String CONF_OUTPUT_PATH = "writer.output.path";
public AbstractWriter(Properties prop) throws IOException
{ | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
// Path: src/main/java/com/cloudera/sa/hcu/io/put/hdfs/writer/AbstractWriter.java
import java.io.IOException;
import java.util.Properties;
import com.cloudera.sa.hcu.utils.PropertyUtils;
package com.cloudera.sa.hcu.io.put.hdfs.writer;
public abstract class AbstractWriter
{
protected static final String COMPRESSION_CODEC = "writer.compression.codec";
public static final String CONF_OUTPUT_PATH = "writer.output.path";
public AbstractWriter(Properties prop) throws IOException
{ | String outputPath = PropertyUtils.getStringProperty(prop, CONF_OUTPUT_PATH); |
tmalaska/hadcom.utils | src/main/java/com/cloudera/sa/hcu/io/put/local/reader/LocalOneOrMoreFileColumnReader.java | // Path: src/main/java/com/cloudera/sa/hcu/io/utils/LocalFileUtils.java
// public class LocalFileUtils
// {
//
//
// public static File[] createFileArray(String[] filePathArray)
// {
// ArrayList<File> fileList = new ArrayList<File>();
// File[] tempFileArray;
//
// for (String filePath: filePathArray)
// {
// File origFile = new File(filePath);
//
// if (origFile.isDirectory())
// {
// tempFileArray = origFile.listFiles();
//
// for (File file: tempFileArray)
// {
// fileList.add(file);
// }
// }else
// {
// fileList.add(origFile);
// }
// }
//
// return fileList.toArray(new File[0]);
// }
//
// public static String[] createStringArrayOfFiles(String[] filePathArray)
// {
// ArrayList<String> filePathList = new ArrayList<String>();
// File[] tempFileArray;
//
// for (String filePath: filePathArray)
// {
// File origFile = new File(filePath);
//
// if (origFile.isDirectory())
// {
// tempFileArray = origFile.listFiles();
//
// for (File file: tempFileArray)
// {
// filePathList.add(file.getAbsolutePath());
// }
// }else
// {
// filePathList.add(origFile.getAbsolutePath());
// }
// }
//
// return filePathList.toArray(new String[0]);
// }
//
//
// }
| import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.zip.GZIPInputStream;
import java.util.Properties;
import com.cloudera.sa.hcu.io.utils.LocalFileUtils;; | package com.cloudera.sa.hcu.io.put.local.reader;
public abstract class LocalOneOrMoreFileColumnReader extends AbstractLocalFileColumnReader
{
public LocalOneOrMoreFileColumnReader(Properties prop) throws Exception
{
super(prop);
loadFile(inputPaths);
}
protected BufferedReader reader;
protected File[] fileArray;
protected int fileIndex = 0;
protected void loadFile(String[] filePathArray) throws IOException
{ | // Path: src/main/java/com/cloudera/sa/hcu/io/utils/LocalFileUtils.java
// public class LocalFileUtils
// {
//
//
// public static File[] createFileArray(String[] filePathArray)
// {
// ArrayList<File> fileList = new ArrayList<File>();
// File[] tempFileArray;
//
// for (String filePath: filePathArray)
// {
// File origFile = new File(filePath);
//
// if (origFile.isDirectory())
// {
// tempFileArray = origFile.listFiles();
//
// for (File file: tempFileArray)
// {
// fileList.add(file);
// }
// }else
// {
// fileList.add(origFile);
// }
// }
//
// return fileList.toArray(new File[0]);
// }
//
// public static String[] createStringArrayOfFiles(String[] filePathArray)
// {
// ArrayList<String> filePathList = new ArrayList<String>();
// File[] tempFileArray;
//
// for (String filePath: filePathArray)
// {
// File origFile = new File(filePath);
//
// if (origFile.isDirectory())
// {
// tempFileArray = origFile.listFiles();
//
// for (File file: tempFileArray)
// {
// filePathList.add(file.getAbsolutePath());
// }
// }else
// {
// filePathList.add(origFile.getAbsolutePath());
// }
// }
//
// return filePathList.toArray(new String[0]);
// }
//
//
// }
// Path: src/main/java/com/cloudera/sa/hcu/io/put/local/reader/LocalOneOrMoreFileColumnReader.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.zip.GZIPInputStream;
import java.util.Properties;
import com.cloudera.sa.hcu.io.utils.LocalFileUtils;;
package com.cloudera.sa.hcu.io.put.local.reader;
public abstract class LocalOneOrMoreFileColumnReader extends AbstractLocalFileColumnReader
{
public LocalOneOrMoreFileColumnReader(Properties prop) throws Exception
{
super(prop);
loadFile(inputPaths);
}
protected BufferedReader reader;
protected File[] fileArray;
protected int fileIndex = 0;
protected void loadFile(String[] filePathArray) throws IOException
{ | fileArray = LocalFileUtils.createFileArray(filePathArray); |
tmalaska/hadcom.utils | src/main/java/com/cloudera/sa/hcu/io/put/local/reader/VaribleLengthFlatFileReader.java | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
| import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import com.cloudera.sa.hcu.utils.PropertyUtils; | package com.cloudera.sa.hcu.io.put.local.reader;
public class VaribleLengthFlatFileReader extends LocalOneOrMoreFileColumnReader
{
public static final String CONF_ROW_TYPE_START_INDEX = "reader.row.type.start.index";
public static final String CONF_ROW_TYPE_LENGTH = "reader.row.type.length";
int rowTypeStartIndex = 0;
int rowTypeLength = 0;
Map<String, int[]> rowTypeLengthArrayMap;
String currentRowType;
public VaribleLengthFlatFileReader(String[] filePaths, Properties p) throws Exception
{
super(p);
}
@Override
protected void init(String[] inputPaths, Properties p) throws IOException
{ | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
// Path: src/main/java/com/cloudera/sa/hcu/io/put/local/reader/VaribleLengthFlatFileReader.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import com.cloudera.sa.hcu.utils.PropertyUtils;
package com.cloudera.sa.hcu.io.put.local.reader;
public class VaribleLengthFlatFileReader extends LocalOneOrMoreFileColumnReader
{
public static final String CONF_ROW_TYPE_START_INDEX = "reader.row.type.start.index";
public static final String CONF_ROW_TYPE_LENGTH = "reader.row.type.length";
int rowTypeStartIndex = 0;
int rowTypeLength = 0;
Map<String, int[]> rowTypeLengthArrayMap;
String currentRowType;
public VaribleLengthFlatFileReader(String[] filePaths, Properties p) throws Exception
{
super(p);
}
@Override
protected void init(String[] inputPaths, Properties p) throws IOException
{ | this.rowTypeLength = PropertyUtils.getIntProperty(p, CONF_ROW_TYPE_LENGTH); |
tmalaska/hadcom.utils | src/main/java/com/cloudera/sa/hcu/io/put/local/reader/DelimiterReader.java | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
| import java.io.BufferedReader;
import java.io.IOException;
import java.util.Properties;
import java.util.regex.Pattern;
import com.cloudera.sa.hcu.utils.PropertyUtils; | package com.cloudera.sa.hcu.io.put.local.reader;
public class DelimiterReader extends LocalOneOrMoreFileColumnReader
{
Pattern pattern;
BufferedReader reader;
public static final String CONF_DELIMITER_REGEX = DELIMITER_REGEX;
public DelimiterReader( Properties p) throws Exception
{
super( p);
}
@Override
protected void init(String[] inputPaths, Properties p) throws IOException
{ | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
// Path: src/main/java/com/cloudera/sa/hcu/io/put/local/reader/DelimiterReader.java
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Properties;
import java.util.regex.Pattern;
import com.cloudera.sa.hcu.utils.PropertyUtils;
package com.cloudera.sa.hcu.io.put.local.reader;
public class DelimiterReader extends LocalOneOrMoreFileColumnReader
{
Pattern pattern;
BufferedReader reader;
public static final String CONF_DELIMITER_REGEX = DELIMITER_REGEX;
public DelimiterReader( Properties p) throws Exception
{
super( p);
}
@Override
protected void init(String[] inputPaths, Properties p) throws IOException
{ | pattern = Pattern.compile(PropertyUtils.getStringProperty(p, CONF_DELIMITER_REGEX)); |
tmalaska/hadcom.utils | src/main/java/com/cloudera/sa/hcu/io/put/hdfs/writer/AvroWriter.java | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
| import java.io.IOException;
import java.util.Properties;
import org.apache.avro.Schema;
import org.apache.avro.Schema.Type;
import org.apache.avro.file.DataFileWriter;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.DatumWriter;
import org.apache.avro.util.Utf8;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import com.cloudera.sa.hcu.utils.PropertyUtils; | package com.cloudera.sa.hcu.io.put.hdfs.writer;
public class AvroWriter extends AbstractWriter
{
DataFileWriter<GenericRecord> dataFileWriter;
Schema schema;
public static final String CONF_SCHEMA_JSON = "avro.writer.schema.json";
public static final String CONF_COMPRESSION_CODEC = COMPRESSION_CODEC;
public AvroWriter(Properties p) throws Exception
{
super( p);
}
public AvroWriter(String outputPath, String schemaJson, String compressionCodec) throws IOException
{
super(makeProperties(outputPath, schemaJson, compressionCodec));
}
private static Properties makeProperties(String outputPath, String schemaJson, String compressionCodec)
{
Properties p = new Properties();
p.setProperty(CONF_OUTPUT_PATH, outputPath);
p.setProperty(CONF_SCHEMA_JSON, schemaJson);
p.setProperty(CONF_COMPRESSION_CODEC, compressionCodec);
return p;
}
@Override
protected void init(String outputPath, Properties p) throws IOException
{ | // Path: src/main/java/com/cloudera/sa/hcu/utils/PropertyUtils.java
// public class PropertyUtils
// {
//
// public static String getStringProperty(Properties p, String key)
// {
// String value = p.getProperty(key);
// if (value == null)
// {
// throw new RuntimeException("Property:" + key + " is required.");
// }
// return value;
// }
//
// public static int getIntProperty(Properties p, String key)
// {
// try
// {
// return Integer.parseInt(getStringProperty(p, key));
// }catch(NumberFormatException e)
// {
// throw new RuntimeException("Property:" + key + " is most be an int. Value '" + getStringProperty(p, key) + "' is not valid", e);
// }
// }
//
//
// public static CompressionCodec getCompressionCodecProperty(Properties p , String key)
// {
// String value = getStringProperty(p, key).toLowerCase();
//
// if (value.equals("snappy"))
// {
// return new SnappyCodec();
// }else if (value.equals("gzip"))
// {
// return new GzipCodec();
// }else if (value.equals("bzip2"))
// {
// return new BZip2Codec();
// }else
// {
// return new SnappyCodec();
// }
// }
//
// private static Pattern pattern = Pattern.compile(",");
//
// public static String convertIntArrayToString(int[] intArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (int val: intArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
// public static String convertStringArrayToString(String[] strArray)
// {
// StringBuilder strBuilder = new StringBuilder();
// for (String val: strArray)
// {
// strBuilder.append(val + ",");
// }
// strBuilder.delete(strBuilder.length() - 1, strBuilder.length());
//
// return strBuilder.toString();
// }
//
//
//
// public static int[] getIntArrayProperty(Properties p, String key)
// {
// String[] fieldLengthStrings = pattern.split(getStringProperty(p,key));
// int[] results = new int[fieldLengthStrings.length];
//
// for (int i = 0; i < fieldLengthStrings.length; i++)
// {
// results[i] = Integer.parseInt(fieldLengthStrings[i]);
// }
//
// return results;
// }
//
// }
// Path: src/main/java/com/cloudera/sa/hcu/io/put/hdfs/writer/AvroWriter.java
import java.io.IOException;
import java.util.Properties;
import org.apache.avro.Schema;
import org.apache.avro.Schema.Type;
import org.apache.avro.file.DataFileWriter;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.DatumWriter;
import org.apache.avro.util.Utf8;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import com.cloudera.sa.hcu.utils.PropertyUtils;
package com.cloudera.sa.hcu.io.put.hdfs.writer;
public class AvroWriter extends AbstractWriter
{
DataFileWriter<GenericRecord> dataFileWriter;
Schema schema;
public static final String CONF_SCHEMA_JSON = "avro.writer.schema.json";
public static final String CONF_COMPRESSION_CODEC = COMPRESSION_CODEC;
public AvroWriter(Properties p) throws Exception
{
super( p);
}
public AvroWriter(String outputPath, String schemaJson, String compressionCodec) throws IOException
{
super(makeProperties(outputPath, schemaJson, compressionCodec));
}
private static Properties makeProperties(String outputPath, String schemaJson, String compressionCodec)
{
Properties p = new Properties();
p.setProperty(CONF_OUTPUT_PATH, outputPath);
p.setProperty(CONF_SCHEMA_JSON, schemaJson);
p.setProperty(CONF_COMPRESSION_CODEC, compressionCodec);
return p;
}
@Override
protected void init(String outputPath, Properties p) throws IOException
{ | schema = (new Schema.Parser()).parse(PropertyUtils.getStringProperty(p, CONF_SCHEMA_JSON)); |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyLamp.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public interface Lamp extends Thing {
//
// public final static String STATE = "state";
// public final static String LEVEL = "level";
// public final static String COLOR = "color";
//
//
// public static enum State {
// OFF, ON;
// }
//
// public State getState();
//
// public void on();
//
// public void off();
//
// public void toggle();
//
// public int getLevel();
//
// public void setLevel(final int level);
//
// public void incrementLevel(final int increment);
//
// public void decrementLevel(final int decrement);
//
// public Color getColor();
//
// public void setColor(Color c);
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
| import java.util.UUID;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.lamp.Lamp;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import java.awt.Color; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.Lamp",
configurationPolicy=ConfigurationPolicy.REQUIRE, | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public interface Lamp extends Thing {
//
// public final static String STATE = "state";
// public final static String LEVEL = "level";
// public final static String COLOR = "color";
//
//
// public static enum State {
// OFF, ON;
// }
//
// public State getState();
//
// public void on();
//
// public void off();
//
// public void toggle();
//
// public int getLevel();
//
// public void setLevel(final int level);
//
// public void incrementLevel(final int increment);
//
// public void decrementLevel(final int decrement);
//
// public Color getColor();
//
// public void setColor(Color c);
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyLamp.java
import java.util.UUID;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.lamp.Lamp;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import java.awt.Color;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.Lamp",
configurationPolicy=ConfigurationPolicy.REQUIRE, | service={Lamp.class, Thing.class}, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyLamp.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public interface Lamp extends Thing {
//
// public final static String STATE = "state";
// public final static String LEVEL = "level";
// public final static String COLOR = "color";
//
//
// public static enum State {
// OFF, ON;
// }
//
// public State getState();
//
// public void on();
//
// public void off();
//
// public void toggle();
//
// public int getLevel();
//
// public void setLevel(final int level);
//
// public void incrementLevel(final int increment);
//
// public void decrementLevel(final int decrement);
//
// public Color getColor();
//
// public void setColor(Color c);
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
| import java.util.UUID;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.lamp.Lamp;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import java.awt.Color; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.Lamp",
configurationPolicy=ConfigurationPolicy.REQUIRE, | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public interface Lamp extends Thing {
//
// public final static String STATE = "state";
// public final static String LEVEL = "level";
// public final static String COLOR = "color";
//
//
// public static enum State {
// OFF, ON;
// }
//
// public State getState();
//
// public void on();
//
// public void off();
//
// public void toggle();
//
// public int getLevel();
//
// public void setLevel(final int level);
//
// public void incrementLevel(final int increment);
//
// public void decrementLevel(final int decrement);
//
// public Color getColor();
//
// public void setColor(Color c);
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyLamp.java
import java.util.UUID;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.lamp.Lamp;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import java.awt.Color;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.Lamp",
configurationPolicy=ConfigurationPolicy.REQUIRE, | service={Lamp.class, Thing.class}, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/LampAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public interface Lamp extends Thing {
//
// public final static String STATE = "state";
// public final static String LEVEL = "level";
// public final static String COLOR = "color";
//
//
// public static enum State {
// OFF, ON;
// }
//
// public State getState();
//
// public void on();
//
// public void off();
//
// public void toggle();
//
// public int getLevel();
//
// public void setLevel(final int level);
//
// public void incrementLevel(final int increment);
//
// public void decrementLevel(final int decrement);
//
// public Color getColor();
//
// public void setColor(Color c);
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public static enum State {
// OFF, ON;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.dyamand.sensors.lighting.LightServiceType;
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.lamp.Lamp;
import be.iminds.iot.things.api.lamp.Lamp.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import java.awt.Color; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class LampAdapter implements ServiceAdapter {
@Override
public String getType(){
return "lamp";
}
@Override
public String[] getTargets() {
return new String[] { be.iminds.iot.things.api.Thing.class.getName(), | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public interface Lamp extends Thing {
//
// public final static String STATE = "state";
// public final static String LEVEL = "level";
// public final static String COLOR = "color";
//
//
// public static enum State {
// OFF, ON;
// }
//
// public State getState();
//
// public void on();
//
// public void off();
//
// public void toggle();
//
// public int getLevel();
//
// public void setLevel(final int level);
//
// public void incrementLevel(final int increment);
//
// public void decrementLevel(final int decrement);
//
// public Color getColor();
//
// public void setColor(Color c);
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public static enum State {
// OFF, ON;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/LampAdapter.java
import org.dyamand.sensors.lighting.LightServiceType;
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.lamp.Lamp;
import be.iminds.iot.things.api.lamp.Lamp.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import java.awt.Color;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class LampAdapter implements ServiceAdapter {
@Override
public String getType(){
return "lamp";
}
@Override
public String[] getTargets() {
return new String[] { be.iminds.iot.things.api.Thing.class.getName(), | be.iminds.iot.things.api.lamp.Lamp.class.getName() }; |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/LampAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public interface Lamp extends Thing {
//
// public final static String STATE = "state";
// public final static String LEVEL = "level";
// public final static String COLOR = "color";
//
//
// public static enum State {
// OFF, ON;
// }
//
// public State getState();
//
// public void on();
//
// public void off();
//
// public void toggle();
//
// public int getLevel();
//
// public void setLevel(final int level);
//
// public void incrementLevel(final int increment);
//
// public void decrementLevel(final int decrement);
//
// public Color getColor();
//
// public void setColor(Color c);
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public static enum State {
// OFF, ON;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.dyamand.sensors.lighting.LightServiceType;
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.lamp.Lamp;
import be.iminds.iot.things.api.lamp.Lamp.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import java.awt.Color; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class LampAdapter implements ServiceAdapter {
@Override
public String getType(){
return "lamp";
}
@Override
public String[] getTargets() {
return new String[] { be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.lamp.Lamp.class.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.lighting.Light)) {
throw new Exception("Cannot translate object!");
}
// some name confusion here ... in DYAMAND it is called light but we
// call it lamp to avoid confusion with light sensor
final Lamp lamp = new AdaptedLight(
(org.dyamand.sensors.lighting.Light) source);
return lamp;
}
@Override | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public interface Lamp extends Thing {
//
// public final static String STATE = "state";
// public final static String LEVEL = "level";
// public final static String COLOR = "color";
//
//
// public static enum State {
// OFF, ON;
// }
//
// public State getState();
//
// public void on();
//
// public void off();
//
// public void toggle();
//
// public int getLevel();
//
// public void setLevel(final int level);
//
// public void incrementLevel(final int increment);
//
// public void decrementLevel(final int decrement);
//
// public Color getColor();
//
// public void setColor(Color c);
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public static enum State {
// OFF, ON;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/LampAdapter.java
import org.dyamand.sensors.lighting.LightServiceType;
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.lamp.Lamp;
import be.iminds.iot.things.api.lamp.Lamp.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import java.awt.Color;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class LampAdapter implements ServiceAdapter {
@Override
public String getType(){
return "lamp";
}
@Override
public String[] getTargets() {
return new String[] { be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.lamp.Lamp.class.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.lighting.Light)) {
throw new Exception("Cannot translate object!");
}
// some name confusion here ... in DYAMAND it is called light but we
// call it lamp to avoid confusion with light sensor
final Lamp lamp = new AdaptedLight(
(org.dyamand.sensors.lighting.Light) source);
return lamp;
}
@Override | public StateVariable translateStateVariable(final String variable, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/LampAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public interface Lamp extends Thing {
//
// public final static String STATE = "state";
// public final static String LEVEL = "level";
// public final static String COLOR = "color";
//
//
// public static enum State {
// OFF, ON;
// }
//
// public State getState();
//
// public void on();
//
// public void off();
//
// public void toggle();
//
// public int getLevel();
//
// public void setLevel(final int level);
//
// public void incrementLevel(final int increment);
//
// public void decrementLevel(final int decrement);
//
// public Color getColor();
//
// public void setColor(Color c);
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public static enum State {
// OFF, ON;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.dyamand.sensors.lighting.LightServiceType;
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.lamp.Lamp;
import be.iminds.iot.things.api.lamp.Lamp.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import java.awt.Color; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class LampAdapter implements ServiceAdapter {
@Override
public String getType(){
return "lamp";
}
@Override
public String[] getTargets() {
return new String[] { be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.lamp.Lamp.class.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.lighting.Light)) {
throw new Exception("Cannot translate object!");
}
// some name confusion here ... in DYAMAND it is called light but we
// call it lamp to avoid confusion with light sensor
final Lamp lamp = new AdaptedLight(
(org.dyamand.sensors.lighting.Light) source);
return lamp;
}
@Override
public StateVariable translateStateVariable(final String variable,
final Object value) throws Exception {
StateVariable translated;
if (variable.equals(LightServiceType.STATE.toString())) {
final boolean on = (Boolean) value; | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public interface Lamp extends Thing {
//
// public final static String STATE = "state";
// public final static String LEVEL = "level";
// public final static String COLOR = "color";
//
//
// public static enum State {
// OFF, ON;
// }
//
// public State getState();
//
// public void on();
//
// public void off();
//
// public void toggle();
//
// public int getLevel();
//
// public void setLevel(final int level);
//
// public void incrementLevel(final int increment);
//
// public void decrementLevel(final int decrement);
//
// public Color getColor();
//
// public void setColor(Color c);
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/lamp/Lamp.java
// public static enum State {
// OFF, ON;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/LampAdapter.java
import org.dyamand.sensors.lighting.LightServiceType;
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.lamp.Lamp;
import be.iminds.iot.things.api.lamp.Lamp.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import java.awt.Color;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class LampAdapter implements ServiceAdapter {
@Override
public String getType(){
return "lamp";
}
@Override
public String[] getTargets() {
return new String[] { be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.lamp.Lamp.class.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.lighting.Light)) {
throw new Exception("Cannot translate object!");
}
// some name confusion here ... in DYAMAND it is called light but we
// call it lamp to avoid confusion with light sensor
final Lamp lamp = new AdaptedLight(
(org.dyamand.sensors.lighting.Light) source);
return lamp;
}
@Override
public StateVariable translateStateVariable(final String variable,
final Object value) throws Exception {
StateVariable translated;
if (variable.equals(LightServiceType.STATE.toString())) {
final boolean on = (Boolean) value; | final State translatedValue = on ? State.ON |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/V4L2CameraAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/camera/Camera.java
// public interface Camera extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OFF, RECORDING;
// }
//
// public static enum Format {
// YUV, RGB, GRAYSCALE, MJPEG;
// }
//
// /**
// * Get the state of the camera
// *
// * @return state of the camera
// */
// public State getState();
//
// /**
// * Return boolean if the camera is on
// */
// public boolean isOn();
//
// /**
// * Get the width of the frames the camera is fetching
// *
// * @return frame width or -1 if not initialized
// */
// public int getWidth();
//
// /**
// * Get the height of the frames the camera is fetching
// *
// * @return frame height or -1 if not initialized
// */
// public int getHeight();
//
// /**
// * Get the current capturing format
// *
// * @return frame format
// */
// public Format getFormat();
//
// /**
// * Return the framerate (frames per second) that is aimed for when having a CameraListener
// *
// * @return framerate
// */
// public float getFramerate();
//
// /**
// * Set framerate
// *
// * @param f framerate to set
// */
// public void setFramerate(float f);
//
// /**
// * Return the latest camera frame when the camera is turned on
// * @return byte array in the camera's current format
// */
// public byte[] getFrame();
//
// /**
// * Turn the camera on
// */
// public void start();
//
// /**
// * Turn the camera on with preferred width,height capture ratio
// *
// * @param width
// * @param height
// */
// public void start(int width, int height, Format format);
//
// /**
// * Stop capturing
// */
// public void stop();
//
// /**
// * Toggle
// */
// public void toggle();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/camera/CameraListener.java
// public interface CameraListener {
//
// public final static String CAMERA_ID = "be.iminds.iot.thing.camera.id";
// public final static String CAMERA_FORMAT = "be.iminds.iot.thing.camera.format";
//
// public void nextFrame(UUID id, Format format, byte[] data);
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import org.dyamand.v4l2.api.V4L2CameraFormat;
import org.dyamand.v4l2.api.V4L2CameraListener;
import org.dyamand.v4l2.api.V4L2CameraServicePOJO;
import org.dyamand.v4l2.api.V4L2CameraServiceType;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import aQute.lib.collections.MultiMap;
import be.iminds.iot.things.api.camera.Camera;
import be.iminds.iot.things.api.camera.CameraListener;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable; |
@Override
public boolean isOn(){
return pojo.isOn();
}
@Override
public Format getFormat() {
return Format.values()[pojo.getFormat()];
}
@Override
public byte[] getFrame() {
return pojo.getFrame();
}
@Override
public float getFramerate() {
return pojo.getFramerate();
}
@Override
public void setFramerate(float f) {
pojo.setFramerate(f);
}
};
}
@Override | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/camera/Camera.java
// public interface Camera extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OFF, RECORDING;
// }
//
// public static enum Format {
// YUV, RGB, GRAYSCALE, MJPEG;
// }
//
// /**
// * Get the state of the camera
// *
// * @return state of the camera
// */
// public State getState();
//
// /**
// * Return boolean if the camera is on
// */
// public boolean isOn();
//
// /**
// * Get the width of the frames the camera is fetching
// *
// * @return frame width or -1 if not initialized
// */
// public int getWidth();
//
// /**
// * Get the height of the frames the camera is fetching
// *
// * @return frame height or -1 if not initialized
// */
// public int getHeight();
//
// /**
// * Get the current capturing format
// *
// * @return frame format
// */
// public Format getFormat();
//
// /**
// * Return the framerate (frames per second) that is aimed for when having a CameraListener
// *
// * @return framerate
// */
// public float getFramerate();
//
// /**
// * Set framerate
// *
// * @param f framerate to set
// */
// public void setFramerate(float f);
//
// /**
// * Return the latest camera frame when the camera is turned on
// * @return byte array in the camera's current format
// */
// public byte[] getFrame();
//
// /**
// * Turn the camera on
// */
// public void start();
//
// /**
// * Turn the camera on with preferred width,height capture ratio
// *
// * @param width
// * @param height
// */
// public void start(int width, int height, Format format);
//
// /**
// * Stop capturing
// */
// public void stop();
//
// /**
// * Toggle
// */
// public void toggle();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/camera/CameraListener.java
// public interface CameraListener {
//
// public final static String CAMERA_ID = "be.iminds.iot.thing.camera.id";
// public final static String CAMERA_FORMAT = "be.iminds.iot.thing.camera.format";
//
// public void nextFrame(UUID id, Format format, byte[] data);
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/V4L2CameraAdapter.java
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import org.dyamand.v4l2.api.V4L2CameraFormat;
import org.dyamand.v4l2.api.V4L2CameraListener;
import org.dyamand.v4l2.api.V4L2CameraServicePOJO;
import org.dyamand.v4l2.api.V4L2CameraServiceType;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import aQute.lib.collections.MultiMap;
import be.iminds.iot.things.api.camera.Camera;
import be.iminds.iot.things.api.camera.CameraListener;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
@Override
public boolean isOn(){
return pojo.isOn();
}
@Override
public Format getFormat() {
return Format.values()[pojo.getFormat()];
}
@Override
public byte[] getFrame() {
return pojo.getFrame();
}
@Override
public float getFramerate() {
return pojo.getFramerate();
}
@Override
public void setFramerate(float f) {
pojo.setFramerate(f);
}
};
}
@Override | public StateVariable translateStateVariable(final String variable, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyMotionSensor.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public interface MotionSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// public State getState();
// }
| import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.motion.MotionSensor;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.MotionSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public interface MotionSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// public State getState();
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyMotionSensor.java
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.motion.MotionSensor;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.MotionSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | service={MotionSensor.class, Thing.class}, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyMotionSensor.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public interface MotionSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// public State getState();
// }
| import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.motion.MotionSensor;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.MotionSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public interface MotionSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// public State getState();
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyMotionSensor.java
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.motion.MotionSensor;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.MotionSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | service={MotionSensor.class, Thing.class}, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyMotionSensor.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public interface MotionSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// public State getState();
// }
| import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.motion.MotionSensor;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.MotionSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE,
service={MotionSensor.class, Thing.class},
property={Thing.TYPE+"=motion"})
public class DummyMotionSensor extends DummyThing implements MotionSensor {
MotionSensor.State state = MotionSensor.State.NO_MOTION;
@Activate
void activate(DummyThingConfig config){
id = UUID.fromString(config.thing_id());
gatewayId = UUID.fromString(config.thing_gateway());
device = config.thing_device();
service = config.thing_service();
type = "motion";
publishOnline();
publishChange(MotionSensor.STATE, getState());
}
@Deactivate
void deactivate(){
publishOffline();
}
@Override
public State getState() {
return state;
}
void setState(MotionSensor.State s){
if(this.state != s){
this.state = s; | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public interface MotionSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// public State getState();
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyMotionSensor.java
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.motion.MotionSensor;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.MotionSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE,
service={MotionSensor.class, Thing.class},
property={Thing.TYPE+"=motion"})
public class DummyMotionSensor extends DummyThing implements MotionSensor {
MotionSensor.State state = MotionSensor.State.NO_MOTION;
@Activate
void activate(DummyThingConfig config){
id = UUID.fromString(config.thing_id());
gatewayId = UUID.fromString(config.thing_gateway());
device = config.thing_device();
service = config.thing_service();
type = "motion";
publishOnline();
publishChange(MotionSensor.STATE, getState());
}
@Deactivate
void deactivate(){
publishOffline();
}
@Override
public State getState() {
return state;
}
void setState(MotionSensor.State s){
if(this.state != s){
this.state = s; | publishChange(Button.STATE, getState()); |
ibcn-cloudlet/firefly | be.iminds.iot.things.rule.engine.provider/src/be/iminds/iot/things/rule/endpoint/RulesRestEndpoint.java | // Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Rule.java
// public interface Rule extends Serializable {
//
// /**
// * Evaluates the rule, returns whether it is triggered or not
// *
// * @param change the change that can cause the rule to trigger
// */
// public boolean evaluate(Change change);
//
// /**
// * Get the type identifier of this Rule
// */
// public String getType();
//
// /**
// * Get the custom human readable description of this Rule
// */
// public String getDescription();
//
// /**
// * Get the DTO representing this Rule
// */
// public RuleDTO getDTO();
//
// /**
// * Notifies when a Thing that is applicable for this rule is online/offline
// * In case of online, the Thing object is set, in case of offline, null is set
// *
// * @param id uuid of the Thing
// * @param thing the Thing object
// */
// public void setThing(UUID id, Thing thing);
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleDTO.java
// public class RuleDTO {
//
// // Types to match the sources
// public String[] sourceTypes;
// // Types to match the destinations
// public String[] destinationTypes;
//
// // Thing UUIDs this rule listens to
// public UUID[] sources;
// // Thing UUIDs this rules actions upon
// public UUID[] destinations;
//
// // Rule type string identifier - from this type a factory can create a rule
// public String type;
// // Description describing this rule
// public String description;
//
// public RuleDTO clone(){
// RuleDTO clone = new RuleDTO();
// clone.sourceTypes = Arrays.copyOf(sourceTypes, sourceTypes.length);
// clone.destinationTypes = Arrays.copyOf(destinationTypes, destinationTypes.length);;
// clone.sources = Arrays.copyOf(sources, sources.length);;
// clone.destinations = Arrays.copyOf(destinations, destinations.length);;
// clone.type = type;
// clone.description = description;
// return clone;
// }
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleEngine.java
// public interface RuleEngine {
//
// public void addRule(Rule rule);
//
// public void removeRule(int index);
//
// public List<Rule> getRules();
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleFactory.java
// public interface RuleFactory {
//
// public Rule createRule(RuleDTO template) throws Exception;
//
// public Collection<RuleDTO> getTemplates();
// }
| import java.util.Collection;
import java.util.List;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import osgi.enroute.rest.api.REST;
import be.iminds.iot.things.rule.api.Rule;
import be.iminds.iot.things.rule.api.RuleDTO;
import be.iminds.iot.things.rule.api.RuleEngine;
import be.iminds.iot.things.rule.api.RuleFactory;
import java.util.ArrayList; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.endpoint;
@Component()
public class RulesRestEndpoint implements REST {
| // Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Rule.java
// public interface Rule extends Serializable {
//
// /**
// * Evaluates the rule, returns whether it is triggered or not
// *
// * @param change the change that can cause the rule to trigger
// */
// public boolean evaluate(Change change);
//
// /**
// * Get the type identifier of this Rule
// */
// public String getType();
//
// /**
// * Get the custom human readable description of this Rule
// */
// public String getDescription();
//
// /**
// * Get the DTO representing this Rule
// */
// public RuleDTO getDTO();
//
// /**
// * Notifies when a Thing that is applicable for this rule is online/offline
// * In case of online, the Thing object is set, in case of offline, null is set
// *
// * @param id uuid of the Thing
// * @param thing the Thing object
// */
// public void setThing(UUID id, Thing thing);
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleDTO.java
// public class RuleDTO {
//
// // Types to match the sources
// public String[] sourceTypes;
// // Types to match the destinations
// public String[] destinationTypes;
//
// // Thing UUIDs this rule listens to
// public UUID[] sources;
// // Thing UUIDs this rules actions upon
// public UUID[] destinations;
//
// // Rule type string identifier - from this type a factory can create a rule
// public String type;
// // Description describing this rule
// public String description;
//
// public RuleDTO clone(){
// RuleDTO clone = new RuleDTO();
// clone.sourceTypes = Arrays.copyOf(sourceTypes, sourceTypes.length);
// clone.destinationTypes = Arrays.copyOf(destinationTypes, destinationTypes.length);;
// clone.sources = Arrays.copyOf(sources, sources.length);;
// clone.destinations = Arrays.copyOf(destinations, destinations.length);;
// clone.type = type;
// clone.description = description;
// return clone;
// }
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleEngine.java
// public interface RuleEngine {
//
// public void addRule(Rule rule);
//
// public void removeRule(int index);
//
// public List<Rule> getRules();
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleFactory.java
// public interface RuleFactory {
//
// public Rule createRule(RuleDTO template) throws Exception;
//
// public Collection<RuleDTO> getTemplates();
// }
// Path: be.iminds.iot.things.rule.engine.provider/src/be/iminds/iot/things/rule/endpoint/RulesRestEndpoint.java
import java.util.Collection;
import java.util.List;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import osgi.enroute.rest.api.REST;
import be.iminds.iot.things.rule.api.Rule;
import be.iminds.iot.things.rule.api.RuleDTO;
import be.iminds.iot.things.rule.api.RuleEngine;
import be.iminds.iot.things.rule.api.RuleFactory;
import java.util.ArrayList;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.endpoint;
@Component()
public class RulesRestEndpoint implements REST {
| private RuleEngine engine; |
ibcn-cloudlet/firefly | be.iminds.iot.things.rule.engine.provider/src/be/iminds/iot/things/rule/endpoint/RulesRestEndpoint.java | // Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Rule.java
// public interface Rule extends Serializable {
//
// /**
// * Evaluates the rule, returns whether it is triggered or not
// *
// * @param change the change that can cause the rule to trigger
// */
// public boolean evaluate(Change change);
//
// /**
// * Get the type identifier of this Rule
// */
// public String getType();
//
// /**
// * Get the custom human readable description of this Rule
// */
// public String getDescription();
//
// /**
// * Get the DTO representing this Rule
// */
// public RuleDTO getDTO();
//
// /**
// * Notifies when a Thing that is applicable for this rule is online/offline
// * In case of online, the Thing object is set, in case of offline, null is set
// *
// * @param id uuid of the Thing
// * @param thing the Thing object
// */
// public void setThing(UUID id, Thing thing);
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleDTO.java
// public class RuleDTO {
//
// // Types to match the sources
// public String[] sourceTypes;
// // Types to match the destinations
// public String[] destinationTypes;
//
// // Thing UUIDs this rule listens to
// public UUID[] sources;
// // Thing UUIDs this rules actions upon
// public UUID[] destinations;
//
// // Rule type string identifier - from this type a factory can create a rule
// public String type;
// // Description describing this rule
// public String description;
//
// public RuleDTO clone(){
// RuleDTO clone = new RuleDTO();
// clone.sourceTypes = Arrays.copyOf(sourceTypes, sourceTypes.length);
// clone.destinationTypes = Arrays.copyOf(destinationTypes, destinationTypes.length);;
// clone.sources = Arrays.copyOf(sources, sources.length);;
// clone.destinations = Arrays.copyOf(destinations, destinations.length);;
// clone.type = type;
// clone.description = description;
// return clone;
// }
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleEngine.java
// public interface RuleEngine {
//
// public void addRule(Rule rule);
//
// public void removeRule(int index);
//
// public List<Rule> getRules();
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleFactory.java
// public interface RuleFactory {
//
// public Rule createRule(RuleDTO template) throws Exception;
//
// public Collection<RuleDTO> getTemplates();
// }
| import java.util.Collection;
import java.util.List;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import osgi.enroute.rest.api.REST;
import be.iminds.iot.things.rule.api.Rule;
import be.iminds.iot.things.rule.api.RuleDTO;
import be.iminds.iot.things.rule.api.RuleEngine;
import be.iminds.iot.things.rule.api.RuleFactory;
import java.util.ArrayList; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.endpoint;
@Component()
public class RulesRestEndpoint implements REST {
private RuleEngine engine; | // Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Rule.java
// public interface Rule extends Serializable {
//
// /**
// * Evaluates the rule, returns whether it is triggered or not
// *
// * @param change the change that can cause the rule to trigger
// */
// public boolean evaluate(Change change);
//
// /**
// * Get the type identifier of this Rule
// */
// public String getType();
//
// /**
// * Get the custom human readable description of this Rule
// */
// public String getDescription();
//
// /**
// * Get the DTO representing this Rule
// */
// public RuleDTO getDTO();
//
// /**
// * Notifies when a Thing that is applicable for this rule is online/offline
// * In case of online, the Thing object is set, in case of offline, null is set
// *
// * @param id uuid of the Thing
// * @param thing the Thing object
// */
// public void setThing(UUID id, Thing thing);
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleDTO.java
// public class RuleDTO {
//
// // Types to match the sources
// public String[] sourceTypes;
// // Types to match the destinations
// public String[] destinationTypes;
//
// // Thing UUIDs this rule listens to
// public UUID[] sources;
// // Thing UUIDs this rules actions upon
// public UUID[] destinations;
//
// // Rule type string identifier - from this type a factory can create a rule
// public String type;
// // Description describing this rule
// public String description;
//
// public RuleDTO clone(){
// RuleDTO clone = new RuleDTO();
// clone.sourceTypes = Arrays.copyOf(sourceTypes, sourceTypes.length);
// clone.destinationTypes = Arrays.copyOf(destinationTypes, destinationTypes.length);;
// clone.sources = Arrays.copyOf(sources, sources.length);;
// clone.destinations = Arrays.copyOf(destinations, destinations.length);;
// clone.type = type;
// clone.description = description;
// return clone;
// }
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleEngine.java
// public interface RuleEngine {
//
// public void addRule(Rule rule);
//
// public void removeRule(int index);
//
// public List<Rule> getRules();
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleFactory.java
// public interface RuleFactory {
//
// public Rule createRule(RuleDTO template) throws Exception;
//
// public Collection<RuleDTO> getTemplates();
// }
// Path: be.iminds.iot.things.rule.engine.provider/src/be/iminds/iot/things/rule/endpoint/RulesRestEndpoint.java
import java.util.Collection;
import java.util.List;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import osgi.enroute.rest.api.REST;
import be.iminds.iot.things.rule.api.Rule;
import be.iminds.iot.things.rule.api.RuleDTO;
import be.iminds.iot.things.rule.api.RuleEngine;
import be.iminds.iot.things.rule.api.RuleFactory;
import java.util.ArrayList;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.endpoint;
@Component()
public class RulesRestEndpoint implements REST {
private RuleEngine engine; | private RuleFactory factory; |
ibcn-cloudlet/firefly | be.iminds.iot.things.rule.engine.provider/src/be/iminds/iot/things/rule/endpoint/RulesRestEndpoint.java | // Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Rule.java
// public interface Rule extends Serializable {
//
// /**
// * Evaluates the rule, returns whether it is triggered or not
// *
// * @param change the change that can cause the rule to trigger
// */
// public boolean evaluate(Change change);
//
// /**
// * Get the type identifier of this Rule
// */
// public String getType();
//
// /**
// * Get the custom human readable description of this Rule
// */
// public String getDescription();
//
// /**
// * Get the DTO representing this Rule
// */
// public RuleDTO getDTO();
//
// /**
// * Notifies when a Thing that is applicable for this rule is online/offline
// * In case of online, the Thing object is set, in case of offline, null is set
// *
// * @param id uuid of the Thing
// * @param thing the Thing object
// */
// public void setThing(UUID id, Thing thing);
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleDTO.java
// public class RuleDTO {
//
// // Types to match the sources
// public String[] sourceTypes;
// // Types to match the destinations
// public String[] destinationTypes;
//
// // Thing UUIDs this rule listens to
// public UUID[] sources;
// // Thing UUIDs this rules actions upon
// public UUID[] destinations;
//
// // Rule type string identifier - from this type a factory can create a rule
// public String type;
// // Description describing this rule
// public String description;
//
// public RuleDTO clone(){
// RuleDTO clone = new RuleDTO();
// clone.sourceTypes = Arrays.copyOf(sourceTypes, sourceTypes.length);
// clone.destinationTypes = Arrays.copyOf(destinationTypes, destinationTypes.length);;
// clone.sources = Arrays.copyOf(sources, sources.length);;
// clone.destinations = Arrays.copyOf(destinations, destinations.length);;
// clone.type = type;
// clone.description = description;
// return clone;
// }
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleEngine.java
// public interface RuleEngine {
//
// public void addRule(Rule rule);
//
// public void removeRule(int index);
//
// public List<Rule> getRules();
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleFactory.java
// public interface RuleFactory {
//
// public Rule createRule(RuleDTO template) throws Exception;
//
// public Collection<RuleDTO> getTemplates();
// }
| import java.util.Collection;
import java.util.List;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import osgi.enroute.rest.api.REST;
import be.iminds.iot.things.rule.api.Rule;
import be.iminds.iot.things.rule.api.RuleDTO;
import be.iminds.iot.things.rule.api.RuleEngine;
import be.iminds.iot.things.rule.api.RuleFactory;
import java.util.ArrayList; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.endpoint;
@Component()
public class RulesRestEndpoint implements REST {
private RuleEngine engine;
private RuleFactory factory;
| // Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Rule.java
// public interface Rule extends Serializable {
//
// /**
// * Evaluates the rule, returns whether it is triggered or not
// *
// * @param change the change that can cause the rule to trigger
// */
// public boolean evaluate(Change change);
//
// /**
// * Get the type identifier of this Rule
// */
// public String getType();
//
// /**
// * Get the custom human readable description of this Rule
// */
// public String getDescription();
//
// /**
// * Get the DTO representing this Rule
// */
// public RuleDTO getDTO();
//
// /**
// * Notifies when a Thing that is applicable for this rule is online/offline
// * In case of online, the Thing object is set, in case of offline, null is set
// *
// * @param id uuid of the Thing
// * @param thing the Thing object
// */
// public void setThing(UUID id, Thing thing);
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleDTO.java
// public class RuleDTO {
//
// // Types to match the sources
// public String[] sourceTypes;
// // Types to match the destinations
// public String[] destinationTypes;
//
// // Thing UUIDs this rule listens to
// public UUID[] sources;
// // Thing UUIDs this rules actions upon
// public UUID[] destinations;
//
// // Rule type string identifier - from this type a factory can create a rule
// public String type;
// // Description describing this rule
// public String description;
//
// public RuleDTO clone(){
// RuleDTO clone = new RuleDTO();
// clone.sourceTypes = Arrays.copyOf(sourceTypes, sourceTypes.length);
// clone.destinationTypes = Arrays.copyOf(destinationTypes, destinationTypes.length);;
// clone.sources = Arrays.copyOf(sources, sources.length);;
// clone.destinations = Arrays.copyOf(destinations, destinations.length);;
// clone.type = type;
// clone.description = description;
// return clone;
// }
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleEngine.java
// public interface RuleEngine {
//
// public void addRule(Rule rule);
//
// public void removeRule(int index);
//
// public List<Rule> getRules();
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleFactory.java
// public interface RuleFactory {
//
// public Rule createRule(RuleDTO template) throws Exception;
//
// public Collection<RuleDTO> getTemplates();
// }
// Path: be.iminds.iot.things.rule.engine.provider/src/be/iminds/iot/things/rule/endpoint/RulesRestEndpoint.java
import java.util.Collection;
import java.util.List;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import osgi.enroute.rest.api.REST;
import be.iminds.iot.things.rule.api.Rule;
import be.iminds.iot.things.rule.api.RuleDTO;
import be.iminds.iot.things.rule.api.RuleEngine;
import be.iminds.iot.things.rule.api.RuleFactory;
import java.util.ArrayList;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.endpoint;
@Component()
public class RulesRestEndpoint implements REST {
private RuleEngine engine;
private RuleFactory factory;
| public List<RuleDTO> getRules(){ |
ibcn-cloudlet/firefly | be.iminds.iot.things.rule.engine.provider/src/be/iminds/iot/things/rule/endpoint/RulesRestEndpoint.java | // Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Rule.java
// public interface Rule extends Serializable {
//
// /**
// * Evaluates the rule, returns whether it is triggered or not
// *
// * @param change the change that can cause the rule to trigger
// */
// public boolean evaluate(Change change);
//
// /**
// * Get the type identifier of this Rule
// */
// public String getType();
//
// /**
// * Get the custom human readable description of this Rule
// */
// public String getDescription();
//
// /**
// * Get the DTO representing this Rule
// */
// public RuleDTO getDTO();
//
// /**
// * Notifies when a Thing that is applicable for this rule is online/offline
// * In case of online, the Thing object is set, in case of offline, null is set
// *
// * @param id uuid of the Thing
// * @param thing the Thing object
// */
// public void setThing(UUID id, Thing thing);
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleDTO.java
// public class RuleDTO {
//
// // Types to match the sources
// public String[] sourceTypes;
// // Types to match the destinations
// public String[] destinationTypes;
//
// // Thing UUIDs this rule listens to
// public UUID[] sources;
// // Thing UUIDs this rules actions upon
// public UUID[] destinations;
//
// // Rule type string identifier - from this type a factory can create a rule
// public String type;
// // Description describing this rule
// public String description;
//
// public RuleDTO clone(){
// RuleDTO clone = new RuleDTO();
// clone.sourceTypes = Arrays.copyOf(sourceTypes, sourceTypes.length);
// clone.destinationTypes = Arrays.copyOf(destinationTypes, destinationTypes.length);;
// clone.sources = Arrays.copyOf(sources, sources.length);;
// clone.destinations = Arrays.copyOf(destinations, destinations.length);;
// clone.type = type;
// clone.description = description;
// return clone;
// }
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleEngine.java
// public interface RuleEngine {
//
// public void addRule(Rule rule);
//
// public void removeRule(int index);
//
// public List<Rule> getRules();
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleFactory.java
// public interface RuleFactory {
//
// public Rule createRule(RuleDTO template) throws Exception;
//
// public Collection<RuleDTO> getTemplates();
// }
| import java.util.Collection;
import java.util.List;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import osgi.enroute.rest.api.REST;
import be.iminds.iot.things.rule.api.Rule;
import be.iminds.iot.things.rule.api.RuleDTO;
import be.iminds.iot.things.rule.api.RuleEngine;
import be.iminds.iot.things.rule.api.RuleFactory;
import java.util.ArrayList; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.endpoint;
@Component()
public class RulesRestEndpoint implements REST {
private RuleEngine engine;
private RuleFactory factory;
public List<RuleDTO> getRules(){ | // Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Rule.java
// public interface Rule extends Serializable {
//
// /**
// * Evaluates the rule, returns whether it is triggered or not
// *
// * @param change the change that can cause the rule to trigger
// */
// public boolean evaluate(Change change);
//
// /**
// * Get the type identifier of this Rule
// */
// public String getType();
//
// /**
// * Get the custom human readable description of this Rule
// */
// public String getDescription();
//
// /**
// * Get the DTO representing this Rule
// */
// public RuleDTO getDTO();
//
// /**
// * Notifies when a Thing that is applicable for this rule is online/offline
// * In case of online, the Thing object is set, in case of offline, null is set
// *
// * @param id uuid of the Thing
// * @param thing the Thing object
// */
// public void setThing(UUID id, Thing thing);
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleDTO.java
// public class RuleDTO {
//
// // Types to match the sources
// public String[] sourceTypes;
// // Types to match the destinations
// public String[] destinationTypes;
//
// // Thing UUIDs this rule listens to
// public UUID[] sources;
// // Thing UUIDs this rules actions upon
// public UUID[] destinations;
//
// // Rule type string identifier - from this type a factory can create a rule
// public String type;
// // Description describing this rule
// public String description;
//
// public RuleDTO clone(){
// RuleDTO clone = new RuleDTO();
// clone.sourceTypes = Arrays.copyOf(sourceTypes, sourceTypes.length);
// clone.destinationTypes = Arrays.copyOf(destinationTypes, destinationTypes.length);;
// clone.sources = Arrays.copyOf(sources, sources.length);;
// clone.destinations = Arrays.copyOf(destinations, destinations.length);;
// clone.type = type;
// clone.description = description;
// return clone;
// }
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleEngine.java
// public interface RuleEngine {
//
// public void addRule(Rule rule);
//
// public void removeRule(int index);
//
// public List<Rule> getRules();
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/RuleFactory.java
// public interface RuleFactory {
//
// public Rule createRule(RuleDTO template) throws Exception;
//
// public Collection<RuleDTO> getTemplates();
// }
// Path: be.iminds.iot.things.rule.engine.provider/src/be/iminds/iot/things/rule/endpoint/RulesRestEndpoint.java
import java.util.Collection;
import java.util.List;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import osgi.enroute.rest.api.REST;
import be.iminds.iot.things.rule.api.Rule;
import be.iminds.iot.things.rule.api.RuleDTO;
import be.iminds.iot.things.rule.api.RuleEngine;
import be.iminds.iot.things.rule.api.RuleFactory;
import java.util.ArrayList;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.endpoint;
@Component()
public class RulesRestEndpoint implements REST {
private RuleEngine engine;
private RuleFactory factory;
public List<RuleDTO> getRules(){ | List<Rule> rules = engine.getRules(); |
ibcn-cloudlet/firefly | be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Condition.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
| import java.util.UUID;
import be.iminds.iot.things.api.Thing;
import java.io.Serializable; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.api;
public interface Condition extends Serializable {
public UUID getId();
public String getType();
| // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Condition.java
import java.util.UUID;
import be.iminds.iot.things.api.Thing;
import java.io.Serializable;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.api;
public interface Condition extends Serializable {
public UUID getId();
public String getType();
| public void setThing(Thing thing); |
ibcn-cloudlet/firefly | be.iminds.iot.things.rule.engine.provider/src/be/iminds/iot/things/rule/factory/SimpleAction.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Action.java
// public interface Action extends Serializable {
//
// public UUID getId();
//
// public String getType();
//
// public void setThing(Thing thing);
//
// public void execute();
//
// }
| import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import aQute.lib.converter.Converter;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.rule.api.Action;
import java.awt.Color; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.factory;
public class SimpleAction implements Action {
private final UUID id;
private transient Object thing = null;
private transient Method m;
private final String type;
private final String method;
private Object[] args;
public SimpleAction(
UUID id,
String type,
String method,
Object... args){
this.id = id;
this.type = type;
this.method = method;
this.args = args;
}
@Override
public UUID getId() {
return id;
}
@Override
public String getType() {
return type;
}
@Override | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Action.java
// public interface Action extends Serializable {
//
// public UUID getId();
//
// public String getType();
//
// public void setThing(Thing thing);
//
// public void execute();
//
// }
// Path: be.iminds.iot.things.rule.engine.provider/src/be/iminds/iot/things/rule/factory/SimpleAction.java
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import aQute.lib.converter.Converter;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.rule.api.Action;
import java.awt.Color;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.factory;
public class SimpleAction implements Action {
private final UUID id;
private transient Object thing = null;
private transient Method m;
private final String type;
private final String method;
private Object[] args;
public SimpleAction(
UUID id,
String type,
String method,
Object... args){
this.id = id;
this.type = type;
this.method = method;
this.args = args;
}
@Override
public UUID getId() {
return id;
}
@Override
public String getType() {
return type;
}
@Override | public void setThing(Thing thing) { |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/ButtonAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.button.ButtonServiceType; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class ButtonAdapter implements ServiceAdapter {
@Override
public String getType(){
return "button";
}
@Override
public String[] getTargets() {
return new String[] { be.iminds.iot.things.api.Thing.class.getName(), | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/ButtonAdapter.java
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.button.ButtonServiceType;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class ButtonAdapter implements ServiceAdapter {
@Override
public String getType(){
return "button";
}
@Override
public String[] getTargets() {
return new String[] { be.iminds.iot.things.api.Thing.class.getName(), | be.iminds.iot.things.api.button.Button.class.getName() }; |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/ButtonAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.button.ButtonServiceType; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class ButtonAdapter implements ServiceAdapter {
@Override
public String getType(){
return "button";
}
@Override
public String[] getTargets() {
return new String[] { be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.button.Button.class.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.button.Button)) {
throw new Exception("Cannot translate object!");
}
final Button button = new Button() {
@Override
public State getState() {
final org.dyamand.sensors.button.Button.State s = ((org.dyamand.sensors.button.Button) source)
.getCurrentState();
return State.values()[s.ordinal()];
}
};
return button;
}
@Override | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/ButtonAdapter.java
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.button.ButtonServiceType;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class ButtonAdapter implements ServiceAdapter {
@Override
public String getType(){
return "button";
}
@Override
public String[] getTargets() {
return new String[] { be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.button.Button.class.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.button.Button)) {
throw new Exception("Cannot translate object!");
}
final Button button = new Button() {
@Override
public State getState() {
final org.dyamand.sensors.button.Button.State s = ((org.dyamand.sensors.button.Button) source)
.getCurrentState();
return State.values()[s.ordinal()];
}
};
return button;
}
@Override | public StateVariable translateStateVariable(final String variable, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyThing.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/ChangeEvent.java
// public class ChangeEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public String stateVariable; /* state variable that changed */
// public Object stateValue; /* new value of the state variable */
// public long timestamp; /* timestamp the event was generated */
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OfflineEvent.java
// public class OfflineEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public long timestamp; /* timestamp the event was generated */
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OnlineEvent.java
// public class OnlineEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public String service; /* service of the thing */
// public String device; /* device name of the thing */
// public String type; /* thing type */
// public long timestamp; /* timestamp the event was generated */
//
// }
| import java.util.UUID;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.event.EventAdmin;
import osgi.enroute.dto.api.DTOs;
import osgi.enroute.scheduler.api.Scheduler;
import be.iminds.iot.things.api.event.ChangeEvent;
import be.iminds.iot.things.api.event.OfflineEvent;
import be.iminds.iot.things.api.event.OnlineEvent;
import java.util.Random; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
public abstract class DummyThing {
private int max = 60;
protected Random random = new Random(System.currentTimeMillis());
protected Scheduler scheduler;
protected EventAdmin ea;
protected DTOs dtos;
protected UUID id;
protected UUID gatewayId;
protected String type;
protected String device;
protected String service;
@Reference
void setEventAdmin(EventAdmin ea){
this.ea = ea;
}
@Reference
void setDTOs(DTOs dtos){
this.dtos = dtos;
}
@Reference
void setScheduler(Scheduler scheduler){
this.scheduler = scheduler;
int next = random.nextInt(max)*1000;
scheduler.after(() -> event(), next);
}
void publishOnline(){ | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/ChangeEvent.java
// public class ChangeEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public String stateVariable; /* state variable that changed */
// public Object stateValue; /* new value of the state variable */
// public long timestamp; /* timestamp the event was generated */
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OfflineEvent.java
// public class OfflineEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public long timestamp; /* timestamp the event was generated */
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OnlineEvent.java
// public class OnlineEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public String service; /* service of the thing */
// public String device; /* device name of the thing */
// public String type; /* thing type */
// public long timestamp; /* timestamp the event was generated */
//
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyThing.java
import java.util.UUID;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.event.EventAdmin;
import osgi.enroute.dto.api.DTOs;
import osgi.enroute.scheduler.api.Scheduler;
import be.iminds.iot.things.api.event.ChangeEvent;
import be.iminds.iot.things.api.event.OfflineEvent;
import be.iminds.iot.things.api.event.OnlineEvent;
import java.util.Random;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
public abstract class DummyThing {
private int max = 60;
protected Random random = new Random(System.currentTimeMillis());
protected Scheduler scheduler;
protected EventAdmin ea;
protected DTOs dtos;
protected UUID id;
protected UUID gatewayId;
protected String type;
protected String device;
protected String service;
@Reference
void setEventAdmin(EventAdmin ea){
this.ea = ea;
}
@Reference
void setDTOs(DTOs dtos){
this.dtos = dtos;
}
@Reference
void setScheduler(Scheduler scheduler){
this.scheduler = scheduler;
int next = random.nextInt(max)*1000;
scheduler.after(() -> event(), next);
}
void publishOnline(){ | OnlineEvent e = new OnlineEvent(); |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyThing.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/ChangeEvent.java
// public class ChangeEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public String stateVariable; /* state variable that changed */
// public Object stateValue; /* new value of the state variable */
// public long timestamp; /* timestamp the event was generated */
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OfflineEvent.java
// public class OfflineEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public long timestamp; /* timestamp the event was generated */
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OnlineEvent.java
// public class OnlineEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public String service; /* service of the thing */
// public String device; /* device name of the thing */
// public String type; /* thing type */
// public long timestamp; /* timestamp the event was generated */
//
// }
| import java.util.UUID;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.event.EventAdmin;
import osgi.enroute.dto.api.DTOs;
import osgi.enroute.scheduler.api.Scheduler;
import be.iminds.iot.things.api.event.ChangeEvent;
import be.iminds.iot.things.api.event.OfflineEvent;
import be.iminds.iot.things.api.event.OnlineEvent;
import java.util.Random; | void setDTOs(DTOs dtos){
this.dtos = dtos;
}
@Reference
void setScheduler(Scheduler scheduler){
this.scheduler = scheduler;
int next = random.nextInt(max)*1000;
scheduler.after(() -> event(), next);
}
void publishOnline(){
OnlineEvent e = new OnlineEvent();
e.thingId = id;
e.gatewayId = gatewayId;
e.device = device;
e.service = service;
e.type = type;
e.timestamp = System.currentTimeMillis();
try {
final String topic = "be/iminds/iot/thing/online/"+id;
ea.sendEvent(new org.osgi.service.event.Event(topic, dtos.asMap(e)));
} catch(Exception ex){
System.err.println("Failed to send event "+e);
}
}
void publishOffline(){ | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/ChangeEvent.java
// public class ChangeEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public String stateVariable; /* state variable that changed */
// public Object stateValue; /* new value of the state variable */
// public long timestamp; /* timestamp the event was generated */
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OfflineEvent.java
// public class OfflineEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public long timestamp; /* timestamp the event was generated */
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OnlineEvent.java
// public class OnlineEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public String service; /* service of the thing */
// public String device; /* device name of the thing */
// public String type; /* thing type */
// public long timestamp; /* timestamp the event was generated */
//
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyThing.java
import java.util.UUID;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.event.EventAdmin;
import osgi.enroute.dto.api.DTOs;
import osgi.enroute.scheduler.api.Scheduler;
import be.iminds.iot.things.api.event.ChangeEvent;
import be.iminds.iot.things.api.event.OfflineEvent;
import be.iminds.iot.things.api.event.OnlineEvent;
import java.util.Random;
void setDTOs(DTOs dtos){
this.dtos = dtos;
}
@Reference
void setScheduler(Scheduler scheduler){
this.scheduler = scheduler;
int next = random.nextInt(max)*1000;
scheduler.after(() -> event(), next);
}
void publishOnline(){
OnlineEvent e = new OnlineEvent();
e.thingId = id;
e.gatewayId = gatewayId;
e.device = device;
e.service = service;
e.type = type;
e.timestamp = System.currentTimeMillis();
try {
final String topic = "be/iminds/iot/thing/online/"+id;
ea.sendEvent(new org.osgi.service.event.Event(topic, dtos.asMap(e)));
} catch(Exception ex){
System.err.println("Failed to send event "+e);
}
}
void publishOffline(){ | OfflineEvent e = new OfflineEvent(); |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyThing.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/ChangeEvent.java
// public class ChangeEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public String stateVariable; /* state variable that changed */
// public Object stateValue; /* new value of the state variable */
// public long timestamp; /* timestamp the event was generated */
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OfflineEvent.java
// public class OfflineEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public long timestamp; /* timestamp the event was generated */
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OnlineEvent.java
// public class OnlineEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public String service; /* service of the thing */
// public String device; /* device name of the thing */
// public String type; /* thing type */
// public long timestamp; /* timestamp the event was generated */
//
// }
| import java.util.UUID;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.event.EventAdmin;
import osgi.enroute.dto.api.DTOs;
import osgi.enroute.scheduler.api.Scheduler;
import be.iminds.iot.things.api.event.ChangeEvent;
import be.iminds.iot.things.api.event.OfflineEvent;
import be.iminds.iot.things.api.event.OnlineEvent;
import java.util.Random; | e.thingId = id;
e.gatewayId = gatewayId;
e.device = device;
e.service = service;
e.type = type;
e.timestamp = System.currentTimeMillis();
try {
final String topic = "be/iminds/iot/thing/online/"+id;
ea.sendEvent(new org.osgi.service.event.Event(topic, dtos.asMap(e)));
} catch(Exception ex){
System.err.println("Failed to send event "+e);
}
}
void publishOffline(){
OfflineEvent e = new OfflineEvent();
e.thingId = id;
e.gatewayId = gatewayId;
e.timestamp = System.currentTimeMillis();
try {
final String topic = "be/iminds/iot/thing/offline/"+id;
ea.sendEvent(new org.osgi.service.event.Event(topic, dtos.asMap(e)));
} catch(Exception ex){
System.err.println("Failed to send event "+e);
}
}
void publishChange(String variable, Object value){ | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/ChangeEvent.java
// public class ChangeEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public String stateVariable; /* state variable that changed */
// public Object stateValue; /* new value of the state variable */
// public long timestamp; /* timestamp the event was generated */
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OfflineEvent.java
// public class OfflineEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public long timestamp; /* timestamp the event was generated */
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OnlineEvent.java
// public class OnlineEvent {
//
// public UUID thingId; /* id of the thing */
// public UUID gatewayId; /* gateway that published the event */
// public String service; /* service of the thing */
// public String device; /* device name of the thing */
// public String type; /* thing type */
// public long timestamp; /* timestamp the event was generated */
//
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyThing.java
import java.util.UUID;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.event.EventAdmin;
import osgi.enroute.dto.api.DTOs;
import osgi.enroute.scheduler.api.Scheduler;
import be.iminds.iot.things.api.event.ChangeEvent;
import be.iminds.iot.things.api.event.OfflineEvent;
import be.iminds.iot.things.api.event.OnlineEvent;
import java.util.Random;
e.thingId = id;
e.gatewayId = gatewayId;
e.device = device;
e.service = service;
e.type = type;
e.timestamp = System.currentTimeMillis();
try {
final String topic = "be/iminds/iot/thing/online/"+id;
ea.sendEvent(new org.osgi.service.event.Event(topic, dtos.asMap(e)));
} catch(Exception ex){
System.err.println("Failed to send event "+e);
}
}
void publishOffline(){
OfflineEvent e = new OfflineEvent();
e.thingId = id;
e.gatewayId = gatewayId;
e.timestamp = System.currentTimeMillis();
try {
final String topic = "be/iminds/iot/thing/offline/"+id;
ea.sendEvent(new org.osgi.service.event.Event(topic, dtos.asMap(e)));
} catch(Exception ex){
System.err.println("Failed to send event "+e);
}
}
void publishChange(String variable, Object value){ | ChangeEvent e = new ChangeEvent(); |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyContactSensor.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
| import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.ContactSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyContactSensor.java
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.ContactSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | service={ContactSensor.class, Thing.class}, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyContactSensor.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
| import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.ContactSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyContactSensor.java
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.ContactSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | service={ContactSensor.class, Thing.class}, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyContactSensor.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
| import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.ContactSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE,
service={ContactSensor.class, Thing.class},
property={Thing.TYPE+"=contact"})
public class DummyContactSensor extends DummyThing implements ContactSensor {
ContactSensor.State state = ContactSensor.State.CLOSED;
@Activate
void activate(DummyThingConfig config){
id = UUID.fromString(config.thing_id());
gatewayId = UUID.fromString(config.thing_gateway());
device = config.thing_device();
service = config.thing_service();
type = "contact";
publishOnline();
publishChange(ContactSensor.STATE, getState());
}
@Deactivate
void deactivate(){
publishOffline();
}
@Override
public State getState() {
return state;
}
void setState(ContactSensor.State s){
if(this.state!= s){
this.state = s; | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyContactSensor.java
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.ContactSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE,
service={ContactSensor.class, Thing.class},
property={Thing.TYPE+"=contact"})
public class DummyContactSensor extends DummyThing implements ContactSensor {
ContactSensor.State state = ContactSensor.State.CLOSED;
@Activate
void activate(DummyThingConfig config){
id = UUID.fromString(config.thing_id());
gatewayId = UUID.fromString(config.thing_gateway());
device = config.thing_device();
service = config.thing_service();
type = "contact";
publishOnline();
publishChange(ContactSensor.STATE, getState());
}
@Deactivate
void deactivate(){
publishOffline();
}
@Override
public State getState() {
return state;
}
void setState(ContactSensor.State s){
if(this.state!= s){
this.state = s; | publishChange(Button.STATE, getState()); |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyLightSensor.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightLevel.java
// public class LightLevel extends SensorValue {
//
// public LightLevel(double v) {
// super(v, "lx");
// }
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightSensor.java
// public interface LightSensor extends Thing {
//
// public final static String LIGHTLEVEL = "lightlevel";
//
// public LightLevel getLightLevel();
//
// }
| import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.light.LightLevel;
import be.iminds.iot.things.api.sensor.light.LightSensor;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.LightSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightLevel.java
// public class LightLevel extends SensorValue {
//
// public LightLevel(double v) {
// super(v, "lx");
// }
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightSensor.java
// public interface LightSensor extends Thing {
//
// public final static String LIGHTLEVEL = "lightlevel";
//
// public LightLevel getLightLevel();
//
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyLightSensor.java
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.light.LightLevel;
import be.iminds.iot.things.api.sensor.light.LightSensor;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.LightSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | service={LightSensor.class, Thing.class}, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyLightSensor.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightLevel.java
// public class LightLevel extends SensorValue {
//
// public LightLevel(double v) {
// super(v, "lx");
// }
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightSensor.java
// public interface LightSensor extends Thing {
//
// public final static String LIGHTLEVEL = "lightlevel";
//
// public LightLevel getLightLevel();
//
// }
| import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.light.LightLevel;
import be.iminds.iot.things.api.sensor.light.LightSensor;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.LightSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightLevel.java
// public class LightLevel extends SensorValue {
//
// public LightLevel(double v) {
// super(v, "lx");
// }
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightSensor.java
// public interface LightSensor extends Thing {
//
// public final static String LIGHTLEVEL = "lightlevel";
//
// public LightLevel getLightLevel();
//
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyLightSensor.java
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.light.LightLevel;
import be.iminds.iot.things.api.sensor.light.LightSensor;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.LightSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | service={LightSensor.class, Thing.class}, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyLightSensor.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightLevel.java
// public class LightLevel extends SensorValue {
//
// public LightLevel(double v) {
// super(v, "lx");
// }
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightSensor.java
// public interface LightSensor extends Thing {
//
// public final static String LIGHTLEVEL = "lightlevel";
//
// public LightLevel getLightLevel();
//
// }
| import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.light.LightLevel;
import be.iminds.iot.things.api.sensor.light.LightSensor;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.LightSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE,
service={LightSensor.class, Thing.class},
property={Thing.TYPE+"=light"})
public class DummyLightSensor extends DummyThing implements LightSensor {
private double level = 222;
@Activate
void activate(DummyThingConfig config){
id = UUID.fromString(config.thing_id());
gatewayId = UUID.fromString(config.thing_gateway());
device = config.thing_device();
service = config.thing_service();
type = "light";
publishOnline(); | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightLevel.java
// public class LightLevel extends SensorValue {
//
// public LightLevel(double v) {
// super(v, "lx");
// }
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightSensor.java
// public interface LightSensor extends Thing {
//
// public final static String LIGHTLEVEL = "lightlevel";
//
// public LightLevel getLightLevel();
//
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyLightSensor.java
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.light.LightLevel;
import be.iminds.iot.things.api.sensor.light.LightSensor;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.LightSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE,
service={LightSensor.class, Thing.class},
property={Thing.TYPE+"=light"})
public class DummyLightSensor extends DummyThing implements LightSensor {
private double level = 222;
@Activate
void activate(DummyThingConfig config){
id = UUID.fromString(config.thing_id());
gatewayId = UUID.fromString(config.thing_gateway());
device = config.thing_device();
service = config.thing_service();
type = "light";
publishOnline(); | publishChange(LightSensor.LIGHTLEVEL, new LightLevel(level)); |
ibcn-cloudlet/firefly | be.iminds.iot.things.repository.provider/src/be/iminds/iot/things/repository/provider/ThingsCommands.java | // Path: be.iminds.iot.things.repository.api/src/be/iminds/iot/things/repository/api/ThingsRepository.java
// public interface ThingsRepository {
//
// public ThingDTO getThing(UUID id);
//
// public Collection<ThingDTO> getThings();
//
// public void putThing(ThingDTO thing);
//
// }
//
// Path: be.iminds.iot.things.repository.api/src/be/iminds/iot/things/repository/api/ThingDTO.java
// public class ThingDTO {
//
// // These are provided by the system (hardware)
// public UUID id; /* unique thing id - based on device+service combination */
// public String device; /* device name */
// public String service; /* service name */
// public UUID gateway; /* id of the gateway that provides this thing */
//
// // These are (optionally) provided by the user
// public String name; /* user defined name of the thing */
// public String location; /* user defined location the thing is located */
//
// // Type represents the functionality (interface) of this thing
// public String type; /* type of the device */
//
// public Map<String, Object> state; /* last known state variables */
//
// }
| import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import be.iminds.iot.things.repository.api.ThingsRepository;
import be.iminds.iot.things.repository.api.ThingDTO;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.repository.provider;
@Component(
service=Object.class,
property={"osgi.command.scope=things",
"osgi.command.function=things",
"osgi.command.function=thing",
"osgi.command.function=save",
"osgi.command.function=load"},
immediate=true)
public class ThingsCommands {
| // Path: be.iminds.iot.things.repository.api/src/be/iminds/iot/things/repository/api/ThingsRepository.java
// public interface ThingsRepository {
//
// public ThingDTO getThing(UUID id);
//
// public Collection<ThingDTO> getThings();
//
// public void putThing(ThingDTO thing);
//
// }
//
// Path: be.iminds.iot.things.repository.api/src/be/iminds/iot/things/repository/api/ThingDTO.java
// public class ThingDTO {
//
// // These are provided by the system (hardware)
// public UUID id; /* unique thing id - based on device+service combination */
// public String device; /* device name */
// public String service; /* service name */
// public UUID gateway; /* id of the gateway that provides this thing */
//
// // These are (optionally) provided by the user
// public String name; /* user defined name of the thing */
// public String location; /* user defined location the thing is located */
//
// // Type represents the functionality (interface) of this thing
// public String type; /* type of the device */
//
// public Map<String, Object> state; /* last known state variables */
//
// }
// Path: be.iminds.iot.things.repository.provider/src/be/iminds/iot/things/repository/provider/ThingsCommands.java
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import be.iminds.iot.things.repository.api.ThingsRepository;
import be.iminds.iot.things.repository.api.ThingDTO;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.repository.provider;
@Component(
service=Object.class,
property={"osgi.command.scope=things",
"osgi.command.function=things",
"osgi.command.function=thing",
"osgi.command.function=save",
"osgi.command.function=load"},
immediate=true)
public class ThingsCommands {
| private ThingsRepository repository; |
ibcn-cloudlet/firefly | be.iminds.iot.things.repository.provider/src/be/iminds/iot/things/repository/provider/ThingsCommands.java | // Path: be.iminds.iot.things.repository.api/src/be/iminds/iot/things/repository/api/ThingsRepository.java
// public interface ThingsRepository {
//
// public ThingDTO getThing(UUID id);
//
// public Collection<ThingDTO> getThings();
//
// public void putThing(ThingDTO thing);
//
// }
//
// Path: be.iminds.iot.things.repository.api/src/be/iminds/iot/things/repository/api/ThingDTO.java
// public class ThingDTO {
//
// // These are provided by the system (hardware)
// public UUID id; /* unique thing id - based on device+service combination */
// public String device; /* device name */
// public String service; /* service name */
// public UUID gateway; /* id of the gateway that provides this thing */
//
// // These are (optionally) provided by the user
// public String name; /* user defined name of the thing */
// public String location; /* user defined location the thing is located */
//
// // Type represents the functionality (interface) of this thing
// public String type; /* type of the device */
//
// public Map<String, Object> state; /* last known state variables */
//
// }
| import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import be.iminds.iot.things.repository.api.ThingsRepository;
import be.iminds.iot.things.repository.api.ThingDTO;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.repository.provider;
@Component(
service=Object.class,
property={"osgi.command.scope=things",
"osgi.command.function=things",
"osgi.command.function=thing",
"osgi.command.function=save",
"osgi.command.function=load"},
immediate=true)
public class ThingsCommands {
private ThingsRepository repository;
public void things(){ | // Path: be.iminds.iot.things.repository.api/src/be/iminds/iot/things/repository/api/ThingsRepository.java
// public interface ThingsRepository {
//
// public ThingDTO getThing(UUID id);
//
// public Collection<ThingDTO> getThings();
//
// public void putThing(ThingDTO thing);
//
// }
//
// Path: be.iminds.iot.things.repository.api/src/be/iminds/iot/things/repository/api/ThingDTO.java
// public class ThingDTO {
//
// // These are provided by the system (hardware)
// public UUID id; /* unique thing id - based on device+service combination */
// public String device; /* device name */
// public String service; /* service name */
// public UUID gateway; /* id of the gateway that provides this thing */
//
// // These are (optionally) provided by the user
// public String name; /* user defined name of the thing */
// public String location; /* user defined location the thing is located */
//
// // Type represents the functionality (interface) of this thing
// public String type; /* type of the device */
//
// public Map<String, Object> state; /* last known state variables */
//
// }
// Path: be.iminds.iot.things.repository.provider/src/be/iminds/iot/things/repository/provider/ThingsCommands.java
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import be.iminds.iot.things.repository.api.ThingsRepository;
import be.iminds.iot.things.repository.api.ThingDTO;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.repository.provider;
@Component(
service=Object.class,
property={"osgi.command.scope=things",
"osgi.command.function=things",
"osgi.command.function=thing",
"osgi.command.function=save",
"osgi.command.function=load"},
immediate=true)
public class ThingsCommands {
private ThingsRepository repository;
public void things(){ | for(ThingDTO t : repository.getThings()){ |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/MotionSensorAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public interface MotionSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.motion.MotionSensor;
import be.iminds.iot.things.api.sensor.motion.MotionSensor.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.occupancy.MotionSensorServiceType; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class MotionSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "motion";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(), | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public interface MotionSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/MotionSensorAdapter.java
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.motion.MotionSensor;
import be.iminds.iot.things.api.sensor.motion.MotionSensor.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.occupancy.MotionSensorServiceType;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class MotionSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "motion";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(), | be.iminds.iot.things.api.sensor.motion.MotionSensor.class |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/MotionSensorAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public interface MotionSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.motion.MotionSensor;
import be.iminds.iot.things.api.sensor.motion.MotionSensor.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.occupancy.MotionSensorServiceType; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class MotionSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "motion";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.motion.MotionSensor.class
.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.occupancy.MotionSensor)) {
throw new Exception("Cannot translate object!");
}
final MotionSensor sensor = new MotionSensor() {
@Override | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public interface MotionSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/MotionSensorAdapter.java
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.motion.MotionSensor;
import be.iminds.iot.things.api.sensor.motion.MotionSensor.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.occupancy.MotionSensorServiceType;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class MotionSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "motion";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.motion.MotionSensor.class
.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.occupancy.MotionSensor)) {
throw new Exception("Cannot translate object!");
}
final MotionSensor sensor = new MotionSensor() {
@Override | public State getState() { |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/MotionSensorAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public interface MotionSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.motion.MotionSensor;
import be.iminds.iot.things.api.sensor.motion.MotionSensor.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.occupancy.MotionSensorServiceType; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class MotionSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "motion";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.motion.MotionSensor.class
.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.occupancy.MotionSensor)) {
throw new Exception("Cannot translate object!");
}
final MotionSensor sensor = new MotionSensor() {
@Override
public State getState() {
final org.dyamand.sensors.occupancy.MotionSensor m = (org.dyamand.sensors.occupancy.MotionSensor) source;
return m.isMotionDetected() ? State.MOTION : State.NO_MOTION;
}
};
return sensor;
}
@Override | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public interface MotionSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/motion/MotionSensor.java
// public static enum State {
// MOTION, NO_MOTION;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/MotionSensorAdapter.java
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.motion.MotionSensor;
import be.iminds.iot.things.api.sensor.motion.MotionSensor.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.occupancy.MotionSensorServiceType;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class MotionSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "motion";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.motion.MotionSensor.class
.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.occupancy.MotionSensor)) {
throw new Exception("Cannot translate object!");
}
final MotionSensor sensor = new MotionSensor() {
@Override
public State getState() {
final org.dyamand.sensors.occupancy.MotionSensor m = (org.dyamand.sensors.occupancy.MotionSensor) source;
return m.isMotionDetected() ? State.MOTION : State.NO_MOTION;
}
};
return sensor;
}
@Override | public StateVariable translateStateVariable(final String variable, |
ibcn-cloudlet/firefly | be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Rule.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
| import java.util.UUID;
import be.iminds.iot.things.api.Thing;
import java.io.Serializable; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.api;
/**
* Generic Rule interface
*
* @author tverbele
*
*/
public interface Rule extends Serializable {
/**
* Evaluates the rule, returns whether it is triggered or not
*
* @param change the change that can cause the rule to trigger
*/
public boolean evaluate(Change change);
/**
* Get the type identifier of this Rule
*/
public String getType();
/**
* Get the custom human readable description of this Rule
*/
public String getDescription();
/**
* Get the DTO representing this Rule
*/
public RuleDTO getDTO();
/**
* Notifies when a Thing that is applicable for this rule is online/offline
* In case of online, the Thing object is set, in case of offline, null is set
*
* @param id uuid of the Thing
* @param thing the Thing object
*/ | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Rule.java
import java.util.UUID;
import be.iminds.iot.things.api.Thing;
import java.io.Serializable;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.api;
/**
* Generic Rule interface
*
* @author tverbele
*
*/
public interface Rule extends Serializable {
/**
* Evaluates the rule, returns whether it is triggered or not
*
* @param change the change that can cause the rule to trigger
*/
public boolean evaluate(Change change);
/**
* Get the type identifier of this Rule
*/
public String getType();
/**
* Get the custom human readable description of this Rule
*/
public String getDescription();
/**
* Get the DTO representing this Rule
*/
public RuleDTO getDTO();
/**
* Notifies when a Thing that is applicable for this rule is online/offline
* In case of online, the Thing object is set, in case of offline, null is set
*
* @param id uuid of the Thing
* @param thing the Thing object
*/ | public void setThing(UUID id, Thing thing); |
ibcn-cloudlet/firefly | be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Action.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
| import java.util.UUID;
import be.iminds.iot.things.api.Thing;
import java.io.Serializable; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.api;
public interface Action extends Serializable {
public UUID getId();
public String getType();
| // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Action.java
import java.util.UUID;
import be.iminds.iot.things.api.Thing;
import java.io.Serializable;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.api;
public interface Action extends Serializable {
public UUID getId();
public String getType();
| public void setThing(Thing thing); |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/ContactSensorAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public static enum State {
// OPEN, CLOSED;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.contact.ContactSensor.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.security.DoorWindowContactServiceType; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class ContactSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "contact";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(), | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public static enum State {
// OPEN, CLOSED;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/ContactSensorAdapter.java
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.contact.ContactSensor.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.security.DoorWindowContactServiceType;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class ContactSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "contact";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(), | be.iminds.iot.things.api.sensor.contact.ContactSensor.class |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/ContactSensorAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public static enum State {
// OPEN, CLOSED;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.contact.ContactSensor.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.security.DoorWindowContactServiceType; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class ContactSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "contact";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.contact.ContactSensor.class
.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.security.DoorWindowContact)) {
throw new Exception("Cannot translate object!");
}
final ContactSensor sensor = new ContactSensor() {
@Override | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public static enum State {
// OPEN, CLOSED;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/ContactSensorAdapter.java
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.contact.ContactSensor.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.security.DoorWindowContactServiceType;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class ContactSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "contact";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.contact.ContactSensor.class
.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.security.DoorWindowContact)) {
throw new Exception("Cannot translate object!");
}
final ContactSensor sensor = new ContactSensor() {
@Override | public State getState() { |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/ContactSensorAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public static enum State {
// OPEN, CLOSED;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.contact.ContactSensor.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.security.DoorWindowContactServiceType; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class ContactSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "contact";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.contact.ContactSensor.class
.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.security.DoorWindowContact)) {
throw new Exception("Cannot translate object!");
}
final ContactSensor sensor = new ContactSensor() {
@Override
public State getState() {
final org.dyamand.sensors.security.DoorWindowContact c = (org.dyamand.sensors.security.DoorWindowContact) source;
return c.isOpen() ? State.OPEN : State.CLOSED;
}
};
return sensor;
}
@Override | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public static enum State {
// OPEN, CLOSED;
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/ContactSensorAdapter.java
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.contact.ContactSensor.State;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.security.DoorWindowContactServiceType;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class ContactSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "contact";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.contact.ContactSensor.class
.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.security.DoorWindowContact)) {
throw new Exception("Cannot translate object!");
}
final ContactSensor sensor = new ContactSensor() {
@Override
public State getState() {
final org.dyamand.sensors.security.DoorWindowContact c = (org.dyamand.sensors.security.DoorWindowContact) source;
return c.isOpen() ? State.OPEN : State.CLOSED;
}
};
return sensor;
}
@Override | public StateVariable translateStateVariable(final String variable, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyButton.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
| import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.Button",
configurationPolicy=ConfigurationPolicy.REQUIRE, | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyButton.java
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.Button",
configurationPolicy=ConfigurationPolicy.REQUIRE, | service={Button.class, Thing.class}, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyButton.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
| import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.Button",
configurationPolicy=ConfigurationPolicy.REQUIRE, | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyButton.java
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.Button",
configurationPolicy=ConfigurationPolicy.REQUIRE, | service={Button.class, Thing.class}, |
ibcn-cloudlet/firefly | be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/ConditionActionRule.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
| import java.util.UUID;
import be.iminds.iot.things.api.Thing;
import java.util.List; | @Override
public RuleDTO getDTO() {
RuleDTO dto = new RuleDTO();
dto.description = description;
dto.type = type;
int size = conditions.size();
dto.sourceTypes = new String[size];
dto.sources = new UUID[size];
int i = 0;
for(Condition c : conditions){
dto.sourceTypes[i] = c.getType();
dto.sources[i] = c.getId();
i++;
}
size = actions.size();
dto.destinationTypes = new String[size];
dto.destinations = new UUID[size];
i = 0;
for(Action a : actions){
dto.destinationTypes[i] = a.getType();
dto.destinations[i] = a.getId();
i++;
}
return dto;
}
@Override | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/ConditionActionRule.java
import java.util.UUID;
import be.iminds.iot.things.api.Thing;
import java.util.List;
@Override
public RuleDTO getDTO() {
RuleDTO dto = new RuleDTO();
dto.description = description;
dto.type = type;
int size = conditions.size();
dto.sourceTypes = new String[size];
dto.sources = new UUID[size];
int i = 0;
for(Condition c : conditions){
dto.sourceTypes[i] = c.getType();
dto.sources[i] = c.getId();
i++;
}
size = actions.size();
dto.destinationTypes = new String[size];
dto.destinations = new UUID[size];
i = 0;
for(Action a : actions){
dto.destinationTypes[i] = a.getType();
dto.destinations[i] = a.getId();
i++;
}
return dto;
}
@Override | public void setThing(UUID id, Thing thing) { |
ibcn-cloudlet/firefly | be.iminds.iot.things.rule.engine.provider/src/be/iminds/iot/things/rule/factory/SimpleRule.java | // Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Action.java
// public interface Action extends Serializable {
//
// public UUID getId();
//
// public String getType();
//
// public void setThing(Thing thing);
//
// public void execute();
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Condition.java
// public interface Condition extends Serializable {
//
// public UUID getId();
//
// public String getType();
//
// public void setThing(Thing thing);
//
// public boolean trigger(Change change);
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/ConditionActionRule.java
// public class ConditionActionRule implements Rule {
//
// protected final String type;
// protected final String description;
// protected final List<? extends Condition> conditions;
// protected final List<? extends Action> actions;
//
// public ConditionActionRule(String type, String description,
// List<? extends Condition> conditions,
// List<? extends Action> actions){
//
// this.type = type;
// this.description = description;
// this.conditions = conditions;
// this.actions = actions;
// }
//
// @Override
// public boolean evaluate(Change change) {
// boolean fire = true;
// for(Condition c : conditions){
// fire = fire && c.trigger(change);
// }
// if(fire){
// for(Action a : actions){
// a.execute();
// }
// }
// return fire;
// }
//
// @Override
// public String getType(){
// return type;
// }
//
// @Override
// public String getDescription(){
// return description;
// }
//
// @Override
// public RuleDTO getDTO() {
// RuleDTO dto = new RuleDTO();
// dto.description = description;
// dto.type = type;
//
// int size = conditions.size();
// dto.sourceTypes = new String[size];
// dto.sources = new UUID[size];
// int i = 0;
// for(Condition c : conditions){
// dto.sourceTypes[i] = c.getType();
// dto.sources[i] = c.getId();
// i++;
// }
//
// size = actions.size();
// dto.destinationTypes = new String[size];
// dto.destinations = new UUID[size];
// i = 0;
// for(Action a : actions){
// dto.destinationTypes[i] = a.getType();
// dto.destinations[i] = a.getId();
// i++;
// }
//
// return dto;
// }
//
// @Override
// public void setThing(UUID id, Thing thing) {
// for(Condition c : conditions){
// if(id.equals(c.getId())){
// c.setThing(thing);
// }
// }
// for(Action a : actions){
// if(id.equals(a.getId())){
// a.setThing(thing);
// }
// }
// }
// }
| import java.util.List;
import java.util.UUID;
import be.iminds.iot.things.rule.api.Action;
import be.iminds.iot.things.rule.api.Condition;
import be.iminds.iot.things.rule.api.ConditionActionRule;
import java.util.ArrayList; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.factory;
public class SimpleRule extends ConditionActionRule {
public SimpleRule(String type, String description,
List<SimpleCondition> conditions, List<SimpleAction> actions) {
super(type, description, conditions, actions);
}
public SimpleRule clone(String description, UUID[] sources, UUID[] destinations) throws Exception {
// TODO check whether sources.length and destinations.length is ok?
List<SimpleCondition> clonedConditions = new ArrayList<SimpleCondition>(sources.length);
int i = 0; | // Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Action.java
// public interface Action extends Serializable {
//
// public UUID getId();
//
// public String getType();
//
// public void setThing(Thing thing);
//
// public void execute();
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Condition.java
// public interface Condition extends Serializable {
//
// public UUID getId();
//
// public String getType();
//
// public void setThing(Thing thing);
//
// public boolean trigger(Change change);
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/ConditionActionRule.java
// public class ConditionActionRule implements Rule {
//
// protected final String type;
// protected final String description;
// protected final List<? extends Condition> conditions;
// protected final List<? extends Action> actions;
//
// public ConditionActionRule(String type, String description,
// List<? extends Condition> conditions,
// List<? extends Action> actions){
//
// this.type = type;
// this.description = description;
// this.conditions = conditions;
// this.actions = actions;
// }
//
// @Override
// public boolean evaluate(Change change) {
// boolean fire = true;
// for(Condition c : conditions){
// fire = fire && c.trigger(change);
// }
// if(fire){
// for(Action a : actions){
// a.execute();
// }
// }
// return fire;
// }
//
// @Override
// public String getType(){
// return type;
// }
//
// @Override
// public String getDescription(){
// return description;
// }
//
// @Override
// public RuleDTO getDTO() {
// RuleDTO dto = new RuleDTO();
// dto.description = description;
// dto.type = type;
//
// int size = conditions.size();
// dto.sourceTypes = new String[size];
// dto.sources = new UUID[size];
// int i = 0;
// for(Condition c : conditions){
// dto.sourceTypes[i] = c.getType();
// dto.sources[i] = c.getId();
// i++;
// }
//
// size = actions.size();
// dto.destinationTypes = new String[size];
// dto.destinations = new UUID[size];
// i = 0;
// for(Action a : actions){
// dto.destinationTypes[i] = a.getType();
// dto.destinations[i] = a.getId();
// i++;
// }
//
// return dto;
// }
//
// @Override
// public void setThing(UUID id, Thing thing) {
// for(Condition c : conditions){
// if(id.equals(c.getId())){
// c.setThing(thing);
// }
// }
// for(Action a : actions){
// if(id.equals(a.getId())){
// a.setThing(thing);
// }
// }
// }
// }
// Path: be.iminds.iot.things.rule.engine.provider/src/be/iminds/iot/things/rule/factory/SimpleRule.java
import java.util.List;
import java.util.UUID;
import be.iminds.iot.things.rule.api.Action;
import be.iminds.iot.things.rule.api.Condition;
import be.iminds.iot.things.rule.api.ConditionActionRule;
import java.util.ArrayList;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.factory;
public class SimpleRule extends ConditionActionRule {
public SimpleRule(String type, String description,
List<SimpleCondition> conditions, List<SimpleAction> actions) {
super(type, description, conditions, actions);
}
public SimpleRule clone(String description, UUID[] sources, UUID[] destinations) throws Exception {
// TODO check whether sources.length and destinations.length is ok?
List<SimpleCondition> clonedConditions = new ArrayList<SimpleCondition>(sources.length);
int i = 0; | for(Condition c : conditions){ |
ibcn-cloudlet/firefly | be.iminds.iot.things.rule.engine.provider/src/be/iminds/iot/things/rule/factory/SimpleRule.java | // Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Action.java
// public interface Action extends Serializable {
//
// public UUID getId();
//
// public String getType();
//
// public void setThing(Thing thing);
//
// public void execute();
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Condition.java
// public interface Condition extends Serializable {
//
// public UUID getId();
//
// public String getType();
//
// public void setThing(Thing thing);
//
// public boolean trigger(Change change);
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/ConditionActionRule.java
// public class ConditionActionRule implements Rule {
//
// protected final String type;
// protected final String description;
// protected final List<? extends Condition> conditions;
// protected final List<? extends Action> actions;
//
// public ConditionActionRule(String type, String description,
// List<? extends Condition> conditions,
// List<? extends Action> actions){
//
// this.type = type;
// this.description = description;
// this.conditions = conditions;
// this.actions = actions;
// }
//
// @Override
// public boolean evaluate(Change change) {
// boolean fire = true;
// for(Condition c : conditions){
// fire = fire && c.trigger(change);
// }
// if(fire){
// for(Action a : actions){
// a.execute();
// }
// }
// return fire;
// }
//
// @Override
// public String getType(){
// return type;
// }
//
// @Override
// public String getDescription(){
// return description;
// }
//
// @Override
// public RuleDTO getDTO() {
// RuleDTO dto = new RuleDTO();
// dto.description = description;
// dto.type = type;
//
// int size = conditions.size();
// dto.sourceTypes = new String[size];
// dto.sources = new UUID[size];
// int i = 0;
// for(Condition c : conditions){
// dto.sourceTypes[i] = c.getType();
// dto.sources[i] = c.getId();
// i++;
// }
//
// size = actions.size();
// dto.destinationTypes = new String[size];
// dto.destinations = new UUID[size];
// i = 0;
// for(Action a : actions){
// dto.destinationTypes[i] = a.getType();
// dto.destinations[i] = a.getId();
// i++;
// }
//
// return dto;
// }
//
// @Override
// public void setThing(UUID id, Thing thing) {
// for(Condition c : conditions){
// if(id.equals(c.getId())){
// c.setThing(thing);
// }
// }
// for(Action a : actions){
// if(id.equals(a.getId())){
// a.setThing(thing);
// }
// }
// }
// }
| import java.util.List;
import java.util.UUID;
import be.iminds.iot.things.rule.api.Action;
import be.iminds.iot.things.rule.api.Condition;
import be.iminds.iot.things.rule.api.ConditionActionRule;
import java.util.ArrayList; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.factory;
public class SimpleRule extends ConditionActionRule {
public SimpleRule(String type, String description,
List<SimpleCondition> conditions, List<SimpleAction> actions) {
super(type, description, conditions, actions);
}
public SimpleRule clone(String description, UUID[] sources, UUID[] destinations) throws Exception {
// TODO check whether sources.length and destinations.length is ok?
List<SimpleCondition> clonedConditions = new ArrayList<SimpleCondition>(sources.length);
int i = 0;
for(Condition c : conditions){
clonedConditions.add(((SimpleCondition)c).clone(sources[i++]));
}
List<SimpleAction> clonedActions = new ArrayList<SimpleAction>(destinations.length);
i = 0; | // Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Action.java
// public interface Action extends Serializable {
//
// public UUID getId();
//
// public String getType();
//
// public void setThing(Thing thing);
//
// public void execute();
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/Condition.java
// public interface Condition extends Serializable {
//
// public UUID getId();
//
// public String getType();
//
// public void setThing(Thing thing);
//
// public boolean trigger(Change change);
//
// }
//
// Path: be.iminds.iot.things.rule.api/src/be/iminds/iot/things/rule/api/ConditionActionRule.java
// public class ConditionActionRule implements Rule {
//
// protected final String type;
// protected final String description;
// protected final List<? extends Condition> conditions;
// protected final List<? extends Action> actions;
//
// public ConditionActionRule(String type, String description,
// List<? extends Condition> conditions,
// List<? extends Action> actions){
//
// this.type = type;
// this.description = description;
// this.conditions = conditions;
// this.actions = actions;
// }
//
// @Override
// public boolean evaluate(Change change) {
// boolean fire = true;
// for(Condition c : conditions){
// fire = fire && c.trigger(change);
// }
// if(fire){
// for(Action a : actions){
// a.execute();
// }
// }
// return fire;
// }
//
// @Override
// public String getType(){
// return type;
// }
//
// @Override
// public String getDescription(){
// return description;
// }
//
// @Override
// public RuleDTO getDTO() {
// RuleDTO dto = new RuleDTO();
// dto.description = description;
// dto.type = type;
//
// int size = conditions.size();
// dto.sourceTypes = new String[size];
// dto.sources = new UUID[size];
// int i = 0;
// for(Condition c : conditions){
// dto.sourceTypes[i] = c.getType();
// dto.sources[i] = c.getId();
// i++;
// }
//
// size = actions.size();
// dto.destinationTypes = new String[size];
// dto.destinations = new UUID[size];
// i = 0;
// for(Action a : actions){
// dto.destinationTypes[i] = a.getType();
// dto.destinations[i] = a.getId();
// i++;
// }
//
// return dto;
// }
//
// @Override
// public void setThing(UUID id, Thing thing) {
// for(Condition c : conditions){
// if(id.equals(c.getId())){
// c.setThing(thing);
// }
// }
// for(Action a : actions){
// if(id.equals(a.getId())){
// a.setThing(thing);
// }
// }
// }
// }
// Path: be.iminds.iot.things.rule.engine.provider/src/be/iminds/iot/things/rule/factory/SimpleRule.java
import java.util.List;
import java.util.UUID;
import be.iminds.iot.things.rule.api.Action;
import be.iminds.iot.things.rule.api.Condition;
import be.iminds.iot.things.rule.api.ConditionActionRule;
import java.util.ArrayList;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.rule.factory;
public class SimpleRule extends ConditionActionRule {
public SimpleRule(String type, String description,
List<SimpleCondition> conditions, List<SimpleAction> actions) {
super(type, description, conditions, actions);
}
public SimpleRule clone(String description, UUID[] sources, UUID[] destinations) throws Exception {
// TODO check whether sources.length and destinations.length is ok?
List<SimpleCondition> clonedConditions = new ArrayList<SimpleCondition>(sources.length);
int i = 0;
for(Condition c : conditions){
clonedConditions.add(((SimpleCondition)c).clone(sources[i++]));
}
List<SimpleAction> clonedActions = new ArrayList<SimpleAction>(destinations.length);
i = 0; | for(Action a : actions){ |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyTemperatureSensor.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/Temperature.java
// public final class Temperature extends SensorValue {
//
// public Temperature(double value){
// super(value, "\u00b0C");
// }
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/TemperatureSensor.java
// public interface TemperatureSensor extends Thing {
//
// public final static String TEMPERATURE = "temperature";
//
// public Temperature getTemperature();
//
// }
| import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.temperature.Temperature;
import be.iminds.iot.things.api.sensor.temperature.TemperatureSensor;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.TemperatureSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/Temperature.java
// public final class Temperature extends SensorValue {
//
// public Temperature(double value){
// super(value, "\u00b0C");
// }
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/TemperatureSensor.java
// public interface TemperatureSensor extends Thing {
//
// public final static String TEMPERATURE = "temperature";
//
// public Temperature getTemperature();
//
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyTemperatureSensor.java
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.temperature.Temperature;
import be.iminds.iot.things.api.sensor.temperature.TemperatureSensor;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.TemperatureSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | service={TemperatureSensor.class, Thing.class}, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyTemperatureSensor.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/Temperature.java
// public final class Temperature extends SensorValue {
//
// public Temperature(double value){
// super(value, "\u00b0C");
// }
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/TemperatureSensor.java
// public interface TemperatureSensor extends Thing {
//
// public final static String TEMPERATURE = "temperature";
//
// public Temperature getTemperature();
//
// }
| import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.temperature.Temperature;
import be.iminds.iot.things.api.sensor.temperature.TemperatureSensor;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.TemperatureSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/Temperature.java
// public final class Temperature extends SensorValue {
//
// public Temperature(double value){
// super(value, "\u00b0C");
// }
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/TemperatureSensor.java
// public interface TemperatureSensor extends Thing {
//
// public final static String TEMPERATURE = "temperature";
//
// public Temperature getTemperature();
//
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyTemperatureSensor.java
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.temperature.Temperature;
import be.iminds.iot.things.api.sensor.temperature.TemperatureSensor;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.TemperatureSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE, | service={TemperatureSensor.class, Thing.class}, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyTemperatureSensor.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/Temperature.java
// public final class Temperature extends SensorValue {
//
// public Temperature(double value){
// super(value, "\u00b0C");
// }
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/TemperatureSensor.java
// public interface TemperatureSensor extends Thing {
//
// public final static String TEMPERATURE = "temperature";
//
// public Temperature getTemperature();
//
// }
| import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.temperature.Temperature;
import be.iminds.iot.things.api.sensor.temperature.TemperatureSensor;
import java.util.UUID; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.TemperatureSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE,
service={TemperatureSensor.class, Thing.class},
property={Thing.TYPE+"=temperature"})
public class DummyTemperatureSensor extends DummyThing implements TemperatureSensor {
private double temperature = 20.2;
@Activate
void activate(DummyThingConfig config){
id = UUID.fromString(config.thing_id());
gatewayId = UUID.fromString(config.thing_gateway());
device = config.thing_device();
service = config.thing_service();
type = "temperature";
publishOnline(); | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
//
// public final static String ID = "thing.id";
// public final static String DEVICE = "thing.device";
// public final static String SERVICE = "thing.service";
// public final static String GATEWAY = "thing.gateway";
// public final static String TYPE = "thing.type";
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/button/Button.java
// public interface Button extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// PRESSED, RELEASED, UP, DOWN
// }
//
// public State getState();
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/contact/ContactSensor.java
// public interface ContactSensor extends Thing {
//
// public final static String STATE = "state";
//
// public static enum State {
// OPEN, CLOSED;
// }
//
// public State getState();
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/Temperature.java
// public final class Temperature extends SensorValue {
//
// public Temperature(double value){
// super(value, "\u00b0C");
// }
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/TemperatureSensor.java
// public interface TemperatureSensor extends Thing {
//
// public final static String TEMPERATURE = "temperature";
//
// public Temperature getTemperature();
//
// }
// Path: be.iminds.iot.things.dummy.adapter/src/be/iminds/iot/things/dummy/DummyTemperatureSensor.java
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.button.Button;
import be.iminds.iot.things.api.sensor.contact.ContactSensor;
import be.iminds.iot.things.api.sensor.temperature.Temperature;
import be.iminds.iot.things.api.sensor.temperature.TemperatureSensor;
import java.util.UUID;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dummy;
@Component(name="be.iminds.iot.things.dummy.TemperatureSensor",
configurationPolicy=ConfigurationPolicy.REQUIRE,
service={TemperatureSensor.class, Thing.class},
property={Thing.TYPE+"=temperature"})
public class DummyTemperatureSensor extends DummyThing implements TemperatureSensor {
private double temperature = 20.2;
@Activate
void activate(DummyThingConfig config){
id = UUID.fromString(config.thing_id());
gatewayId = UUID.fromString(config.thing_gateway());
device = config.thing_device();
service = config.thing_service();
type = "temperature";
publishOnline(); | publishChange(TemperatureSensor.TEMPERATURE, new Temperature(temperature)); |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/TemperatureSensorAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/Temperature.java
// public final class Temperature extends SensorValue {
//
// public Temperature(double value){
// super(value, "\u00b0C");
// }
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/TemperatureSensor.java
// public interface TemperatureSensor extends Thing {
//
// public final static String TEMPERATURE = "temperature";
//
// public Temperature getTemperature();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.temperature.Temperature;
import be.iminds.iot.things.api.sensor.temperature.TemperatureSensor;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.environment.TemperatureSensorServiceType; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class TemperatureSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "temperature";
}
@Override
public String[] getTargets() {
return new String[]{
be.iminds.iot.things.api.Thing.class.getName(), | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/Temperature.java
// public final class Temperature extends SensorValue {
//
// public Temperature(double value){
// super(value, "\u00b0C");
// }
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/TemperatureSensor.java
// public interface TemperatureSensor extends Thing {
//
// public final static String TEMPERATURE = "temperature";
//
// public Temperature getTemperature();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/TemperatureSensorAdapter.java
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.temperature.Temperature;
import be.iminds.iot.things.api.sensor.temperature.TemperatureSensor;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.environment.TemperatureSensorServiceType;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class TemperatureSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "temperature";
}
@Override
public String[] getTargets() {
return new String[]{
be.iminds.iot.things.api.Thing.class.getName(), | be.iminds.iot.things.api.sensor.temperature.TemperatureSensor.class.getName()}; |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/TemperatureSensorAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/Temperature.java
// public final class Temperature extends SensorValue {
//
// public Temperature(double value){
// super(value, "\u00b0C");
// }
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/TemperatureSensor.java
// public interface TemperatureSensor extends Thing {
//
// public final static String TEMPERATURE = "temperature";
//
// public Temperature getTemperature();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.temperature.Temperature;
import be.iminds.iot.things.api.sensor.temperature.TemperatureSensor;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.environment.TemperatureSensorServiceType; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class TemperatureSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "temperature";
}
@Override
public String[] getTargets() {
return new String[]{
be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.temperature.TemperatureSensor.class.getName()};
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.environment.TemperatureSensor)) {
throw new Exception("Cannot translate object!");
}
final TemperatureSensor sensor = new TemperatureSensor() {
@Override | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/Temperature.java
// public final class Temperature extends SensorValue {
//
// public Temperature(double value){
// super(value, "\u00b0C");
// }
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/TemperatureSensor.java
// public interface TemperatureSensor extends Thing {
//
// public final static String TEMPERATURE = "temperature";
//
// public Temperature getTemperature();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/TemperatureSensorAdapter.java
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.temperature.Temperature;
import be.iminds.iot.things.api.sensor.temperature.TemperatureSensor;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.environment.TemperatureSensorServiceType;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class TemperatureSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "temperature";
}
@Override
public String[] getTargets() {
return new String[]{
be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.temperature.TemperatureSensor.class.getName()};
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.environment.TemperatureSensor)) {
throw new Exception("Cannot translate object!");
}
final TemperatureSensor sensor = new TemperatureSensor() {
@Override | public Temperature getTemperature() { |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/TemperatureSensorAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/Temperature.java
// public final class Temperature extends SensorValue {
//
// public Temperature(double value){
// super(value, "\u00b0C");
// }
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/TemperatureSensor.java
// public interface TemperatureSensor extends Thing {
//
// public final static String TEMPERATURE = "temperature";
//
// public Temperature getTemperature();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.temperature.Temperature;
import be.iminds.iot.things.api.sensor.temperature.TemperatureSensor;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.environment.TemperatureSensorServiceType; | be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.temperature.TemperatureSensor.class.getName()};
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.environment.TemperatureSensor)) {
throw new Exception("Cannot translate object!");
}
final TemperatureSensor sensor = new TemperatureSensor() {
@Override
public Temperature getTemperature() {
final org.dyamand.sensors.environment.Temperature t = ((org.dyamand.sensors.environment.TemperatureSensor) source)
.getTemperature();
if(t.getScale().equals(org.dyamand.sensors.environment.Temperature.Scale.CELCIUS)){
final Temperature temp = new Temperature(t.getValue());
return temp;
} else {
System.err.println("For now we only support sensor values in Celcius");
return null;
}
}
};
return sensor;
}
@Override | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/Temperature.java
// public final class Temperature extends SensorValue {
//
// public Temperature(double value){
// super(value, "\u00b0C");
// }
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/temperature/TemperatureSensor.java
// public interface TemperatureSensor extends Thing {
//
// public final static String TEMPERATURE = "temperature";
//
// public Temperature getTemperature();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/TemperatureSensorAdapter.java
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.temperature.Temperature;
import be.iminds.iot.things.api.sensor.temperature.TemperatureSensor;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.environment.TemperatureSensorServiceType;
be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.temperature.TemperatureSensor.class.getName()};
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.environment.TemperatureSensor)) {
throw new Exception("Cannot translate object!");
}
final TemperatureSensor sensor = new TemperatureSensor() {
@Override
public Temperature getTemperature() {
final org.dyamand.sensors.environment.Temperature t = ((org.dyamand.sensors.environment.TemperatureSensor) source)
.getTemperature();
if(t.getScale().equals(org.dyamand.sensors.environment.Temperature.Scale.CELCIUS)){
final Temperature temp = new Temperature(t.getValue());
return temp;
} else {
System.err.println("For now we only support sensor values in Celcius");
return null;
}
}
};
return sensor;
}
@Override | public StateVariable translateStateVariable(final String variable, |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/LightSensorAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightLevel.java
// public class LightLevel extends SensorValue {
//
// public LightLevel(double v) {
// super(v, "lx");
// }
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightSensor.java
// public interface LightSensor extends Thing {
//
// public final static String LIGHTLEVEL = "lightlevel";
//
// public LightLevel getLightLevel();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.light.LightLevel;
import be.iminds.iot.things.api.sensor.light.LightSensor;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.environment.LightSensorServiceType; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class LightSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "light";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(), | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightLevel.java
// public class LightLevel extends SensorValue {
//
// public LightLevel(double v) {
// super(v, "lx");
// }
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightSensor.java
// public interface LightSensor extends Thing {
//
// public final static String LIGHTLEVEL = "lightlevel";
//
// public LightLevel getLightLevel();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/LightSensorAdapter.java
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.light.LightLevel;
import be.iminds.iot.things.api.sensor.light.LightSensor;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.environment.LightSensorServiceType;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class LightSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "light";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(), | be.iminds.iot.things.api.sensor.light.LightSensor.class |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/LightSensorAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightLevel.java
// public class LightLevel extends SensorValue {
//
// public LightLevel(double v) {
// super(v, "lx");
// }
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightSensor.java
// public interface LightSensor extends Thing {
//
// public final static String LIGHTLEVEL = "lightlevel";
//
// public LightLevel getLightLevel();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.light.LightLevel;
import be.iminds.iot.things.api.sensor.light.LightSensor;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.environment.LightSensorServiceType; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class LightSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "light";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.light.LightSensor.class
.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.environment.LightSensor)) {
throw new Exception("Cannot translate object!");
}
final LightSensor sensor = new LightSensor() {
@Override | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightLevel.java
// public class LightLevel extends SensorValue {
//
// public LightLevel(double v) {
// super(v, "lx");
// }
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightSensor.java
// public interface LightSensor extends Thing {
//
// public final static String LIGHTLEVEL = "lightlevel";
//
// public LightLevel getLightLevel();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/LightSensorAdapter.java
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.light.LightLevel;
import be.iminds.iot.things.api.sensor.light.LightSensor;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.environment.LightSensorServiceType;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class LightSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "light";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.light.LightSensor.class
.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.environment.LightSensor)) {
throw new Exception("Cannot translate object!");
}
final LightSensor sensor = new LightSensor() {
@Override | public LightLevel getLightLevel() { |
ibcn-cloudlet/firefly | be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/LightSensorAdapter.java | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightLevel.java
// public class LightLevel extends SensorValue {
//
// public LightLevel(double v) {
// super(v, "lx");
// }
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightSensor.java
// public interface LightSensor extends Thing {
//
// public final static String LIGHTLEVEL = "lightlevel";
//
// public LightLevel getLightLevel();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
| import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.light.LightLevel;
import be.iminds.iot.things.api.sensor.light.LightSensor;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.environment.LightSensorServiceType; | /*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class LightSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "light";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.light.LightSensor.class
.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.environment.LightSensor)) {
throw new Exception("Cannot translate object!");
}
final LightSensor sensor = new LightSensor() {
@Override
public LightLevel getLightLevel() {
final org.dyamand.sensors.environment.LightLevel l = ((org.dyamand.sensors.environment.LightSensor) source)
.getLightLevel();
return new LightLevel(l.getLux());
}
};
return sensor;
}
@Override | // Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightLevel.java
// public class LightLevel extends SensorValue {
//
// public LightLevel(double v) {
// super(v, "lx");
// }
//
// }
//
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/sensor/light/LightSensor.java
// public interface LightSensor extends Thing {
//
// public final static String LIGHTLEVEL = "lightlevel";
//
// public LightLevel getLightLevel();
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/ServiceAdapter.java
// public interface ServiceAdapter {
//
// /**
// * @return the type string
// */
// public String getType();
//
// /**
// * @return The target interfaces to adapt to
// */
// public String[] getTargets();
//
// /**
// * Translate the ServicePojo source to an object that implements all target interfaces
// * @param source The source service
// * @return an object implementing all target interfaces
// */
// public Object getServiceObject(final Object source) throws Exception;
//
// /**
// * Translate a variable name and value to a new state variable
// * @param variable state variable name
// * @param value state variable value
// * @return translated state variable
// */
// public StateVariable translateStateVariable(final String variable,
// final Object value) throws Exception;
//
// }
//
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/StateVariable.java
// public class StateVariable {
//
// public final String name;
// public final Object value;
//
// public StateVariable(final String n, final Object v) {
// this.name = n;
// this.value = v;
// }
//
// public String getName() {
// return this.name;
// }
//
// public Object getValue() {
// return this.value;
// }
// }
// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapters/LightSensorAdapter.java
import org.osgi.service.component.annotations.Component;
import be.iminds.iot.things.api.sensor.light.LightLevel;
import be.iminds.iot.things.api.sensor.light.LightSensor;
import be.iminds.iot.things.dyamand.adapter.ServiceAdapter;
import be.iminds.iot.things.dyamand.adapter.StateVariable;
import org.dyamand.sensors.environment.LightSensorServiceType;
/*******************************************************************************
* Copyright (c) 2015, Tim Verbelen
* Internet Based Communication Networks and Services research group (IBCN),
* Department of Information Technology (INTEC), Ghent University - iMinds.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of Ghent University - iMinds, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package be.iminds.iot.things.dyamand.adapters;
@Component(property={"aiolos.proxy=false"})
public class LightSensorAdapter implements ServiceAdapter {
@Override
public String getType(){
return "light";
}
@Override
public String[] getTargets() {
return new String[] {
be.iminds.iot.things.api.Thing.class.getName(),
be.iminds.iot.things.api.sensor.light.LightSensor.class
.getName() };
}
@Override
public Object getServiceObject(final Object source) throws Exception {
if (!(source instanceof org.dyamand.sensors.environment.LightSensor)) {
throw new Exception("Cannot translate object!");
}
final LightSensor sensor = new LightSensor() {
@Override
public LightLevel getLightLevel() {
final org.dyamand.sensors.environment.LightLevel l = ((org.dyamand.sensors.environment.LightSensor) source)
.getLightLevel();
return new LightLevel(l.getLux());
}
};
return sensor;
}
@Override | public StateVariable translateStateVariable(final String variable, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.